diff options
author | sanine <sanine.not@pm.me> | 2023-05-15 18:47:06 +0000 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-05-15 18:47:06 +0000 |
commit | 16c91c1139d9f03f42c63298f2179822b8d50eb2 (patch) | |
tree | 66b301c2c118478f3fffe474425de24cf121dd26 /proxy.go | |
parent | 8b47f868ce97f50757225a72b958ed483336fd0c (diff) |
properly implement subpath handlingmain
Diffstat (limited to 'proxy.go')
-rw-r--r-- | proxy.go | 14 |
1 files changed, 7 insertions, 7 deletions
@@ -19,7 +19,7 @@ type Endpoint struct { } -func addEndpoint(conf config.Config, s *auth.Sessions, pages page.Pages, e config.Endpoint) { +func addEndpoint(conf config.Config, api config.Api, s *auth.Sessions, pages page.Pages, e config.Endpoint) { log.Infof("proxying endpoint %v to %v", e.Path, e.Address) origin, err := url.Parse(e.Address) if err != nil { @@ -31,22 +31,22 @@ func addEndpoint(conf config.Config, s *auth.Sessions, pages page.Pages, e confi Origin: origin, } - http.HandleFunc(conf.PathPrefix + e.Path, func(w http.ResponseWriter, r *http.Request) { - w.Header().Add("Location", e.Path + "/") + http.HandleFunc(e.Path, func(w http.ResponseWriter, r *http.Request) { + w.Header().Add("Location", api.Prefix + e.Path + "/") w.WriteHeader(http.StatusPermanentRedirect) }) - http.HandleFunc(conf.PathPrefix + e.Path + "/", func(w http.ResponseWriter, r *http.Request) { + http.HandleFunc(e.Path + "/", func(w http.ResponseWriter, r *http.Request) { log.Infof("REQ: %v", r.URL.Path) - proxy(w, r, s, pages, end) + proxy(w, r, api, s, pages, end) }) } -func proxy(w http.ResponseWriter, r *http.Request, s *auth.Sessions, pages page.Pages, end Endpoint) { +func proxy(w http.ResponseWriter, r *http.Request, api config.Api, s *auth.Sessions, pages page.Pages, end Endpoint) { ok := authenticateRequest(r, s) if !ok { - w.Header().Set("Location", "/phlox/login") + w.Header().Set("Location", api.Prefix + api.Login) w.WriteHeader(http.StatusTemporaryRedirect) return } |