Skip to content
This repository was archived by the owner on Nov 23, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions cmd/gateway/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
})
}
Expand Down Expand Up @@ -210,6 +225,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"},
Expand Down
7 changes: 4 additions & 3 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
strip_prefix: "/api/v1/ai"
auth_required: true
target_url: "http://localhost:8091" # Agent Bot service (Python FastAPI)
strip_prefix: "/api/v1/ai" # Strip to match Agent Bot's internal routing
auth_required: true
env_var: "AGENT_BOT_SERVICE_URL"
Loading