From 16c91c1139d9f03f42c63298f2179822b8d50eb2 Mon Sep 17 00:00:00 2001 From: sanine Date: Mon, 15 May 2023 18:47:06 +0000 Subject: properly implement subpath handling --- proxy.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'proxy.go') diff --git a/proxy.go b/proxy.go index 50260f2..d5bfc88 100644 --- a/proxy.go +++ b/proxy.go @@ -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 } -- cgit v1.2.1