internal: fix routing to embedded outpost

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2022-06-16 17:05:27 +02:00
parent e6ecdf8b1d
commit 0a83b04419
1 changed files with 4 additions and 6 deletions

View File

@ -31,8 +31,6 @@ func (ws *WebServer) configureProxy() {
rp := &httputil.ReverseProxy{Director: director} rp := &httputil.ReverseProxy{Director: director}
rp.ErrorHandler = ws.proxyErrorHandler rp.ErrorHandler = ws.proxyErrorHandler
rp.ModifyResponse = ws.proxyModifyResponse rp.ModifyResponse = ws.proxyModifyResponse
proxyMux := ws.m.NewRoute().Subrouter()
proxyMux.Use(sentry.SentryNoSampleMiddleware)
ws.m.PathPrefix("/outpost.goauthentik.io").HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { ws.m.PathPrefix("/outpost.goauthentik.io").HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
if ws.ProxyServer != nil { if ws.ProxyServer != nil {
before := time.Now() before := time.Now()
@ -44,10 +42,10 @@ func (ws *WebServer) configureProxy() {
} }
ws.proxyErrorHandler(rw, r, fmt.Errorf("proxy not running")) ws.proxyErrorHandler(rw, r, fmt.Errorf("proxy not running"))
}) })
proxyMux.Path("/-/health/live/").HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { ws.m.Path("/-/health/live/").HandlerFunc(sentry.SentryNoSample(func(rw http.ResponseWriter, r *http.Request) {
rw.WriteHeader(204) rw.WriteHeader(204)
}) }))
proxyMux.PathPrefix("/").HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { ws.m.PathPrefix("/").HandlerFunc(sentry.SentryNoSample(func(rw http.ResponseWriter, r *http.Request) {
if !ws.p.IsRunning() { if !ws.p.IsRunning() {
ws.proxyErrorHandler(rw, r, fmt.Errorf("authentik core not running yet")) ws.proxyErrorHandler(rw, r, fmt.Errorf("authentik core not running yet"))
return return
@ -66,7 +64,7 @@ func (ws *WebServer) configureProxy() {
}).Observe(float64(time.Since(before))) }).Observe(float64(time.Since(before)))
ws.log.WithField("host", web.GetHost(r)).Trace("routing to application server") ws.log.WithField("host", web.GetHost(r)).Trace("routing to application server")
rp.ServeHTTP(rw, r) rp.ServeHTTP(rw, r)
}) }))
} }
func (ws *WebServer) proxyErrorHandler(rw http.ResponseWriter, req *http.Request, err error) { func (ws *WebServer) proxyErrorHandler(rw http.ResponseWriter, req *http.Request, err error) {