From 83dc61000d366a059aa7a7151dd6ce3365089e62 Mon Sep 17 00:00:00 2001 From: RandithaK Date: Wed, 12 Nov 2025 03:14:13 +0530 Subject: [PATCH 1/3] feat: Update AI service configuration with new target URL and environment variable --- config.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/config.yaml b/config.yaml index 4c841d8..514ce1e 100644 --- a/config.yaml +++ b/config.yaml @@ -115,6 +115,7 @@ services: - name: "ai" path_prefix: "/api/v1/ai/" - target_url: "http://localhost:8089" # Assuming a future port for the FastAPI service + target_url: "http://localhost:8091" # Agent Bot service (Python FastAPI) strip_prefix: "/api/v1/ai" - auth_required: true \ No newline at end of file + auth_required: true + env_var: "AGENT_BOT_SERVICE_URL" \ No newline at end of file From 43540036e0372406a08dd4eb43cfdf0b533964db Mon Sep 17 00:00:00 2001 From: RandithaK Date: Wed, 12 Nov 2025 17:35:46 +0530 Subject: [PATCH 2/3] fix: Update CORS configuration to include new target URL and adjust strip_prefix for AI service --- cmd/gateway/main.go | 1 + config.yaml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/gateway/main.go b/cmd/gateway/main.go index 28089aa..3b7a324 100644 --- a/cmd/gateway/main.go +++ b/cmd/gateway/main.go @@ -210,6 +210,7 @@ func main() { "http://localhost:3000", "http://127.0.0.1:3000", "https://techtorque.vercel.app", + "https://techtorque.randitha.net", }, AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"}, AllowedHeaders: []string{"Accept", "Authorization", "Content-Type", "X-CSRF-Token"}, diff --git a/config.yaml b/config.yaml index 514ce1e..f183b0d 100644 --- a/config.yaml +++ b/config.yaml @@ -116,6 +116,6 @@ services: - name: "ai" path_prefix: "/api/v1/ai/" target_url: "http://localhost:8091" # Agent Bot service (Python FastAPI) - strip_prefix: "/api/v1/ai" + strip_prefix: "" # Don't strip - Agent Bot expects the full path auth_required: true env_var: "AGENT_BOT_SERVICE_URL" \ No newline at end of file From 7dbce6e4b0d51bc8924df632e513cdefaf16fb4a Mon Sep 17 00:00:00 2001 From: RandithaK Date: Wed, 12 Nov 2025 19:16:29 +0530 Subject: [PATCH 3/3] fix: Update reverse proxy to preserve custom headers and adjust strip_prefix for AI service --- cmd/gateway/main.go | 15 +++++++++++++++ config.yaml | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/cmd/gateway/main.go b/cmd/gateway/main.go index 3b7a324..11d369b 100644 --- a/cmd/gateway/main.go +++ b/cmd/gateway/main.go @@ -98,8 +98,21 @@ func newProxy(targetURL, stripPrefix string) (*httputil.ReverseProxy, error) { proxy := httputil.NewSingleHostReverseProxy(target) originalDirector := proxy.Director proxy.Director = func(req *http.Request) { + // Store the custom headers before calling originalDirector + userSubject := req.Header.Get("X-User-Subject") + userRoles := req.Header.Get("X-User-Roles") + originalDirector(req) req.Host = target.Host + + // Re-apply custom headers after originalDirector (which may create a new header map) + if userSubject != "" { + req.Header.Set("X-User-Subject", userSubject) + } + if userRoles != "" { + req.Header.Set("X-User-Roles", userRoles) + } + if stripPrefix != "" { req.URL.Path = strings.TrimPrefix(req.URL.Path, stripPrefix) } @@ -182,6 +195,8 @@ func injectUserInfo(next http.Handler) http.Handler { } logger.Info("Injecting user info into headers", "subject", r.Header.Get("X-User-Subject"), "roles", r.Header.Get("X-User-Roles")) } + // NOTE: The Authorization header is already present in r.Header and will be + // automatically forwarded by the reverse proxy to downstream services next.ServeHTTP(w, r) }) } diff --git a/config.yaml b/config.yaml index f183b0d..dc2027c 100644 --- a/config.yaml +++ b/config.yaml @@ -116,6 +116,6 @@ services: - name: "ai" path_prefix: "/api/v1/ai/" target_url: "http://localhost:8091" # Agent Bot service (Python FastAPI) - strip_prefix: "" # Don't strip - Agent Bot expects the full path + strip_prefix: "/api/v1/ai" # Strip to match Agent Bot's internal routing auth_required: true env_var: "AGENT_BOT_SERVICE_URL" \ No newline at end of file