This commit is contained in:
Milo Schwartz
2024-10-25 21:59:03 -04:00

View File

@@ -37,7 +37,7 @@ func New(ctx context.Context, next http.Handler, config *Config, name string) (h
func (p *Badger) ServeHTTP(rw http.ResponseWriter, req *http.Request) { func (p *Badger) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
cookie, err := req.Cookie(SessionCookieName) cookie, err := req.Cookie(SessionCookieName)
if err != nil { if err != nil {
originalRequestURL := url.QueryEscape(req.URL.String()) originalRequestURL := url.QueryEscape(fmt.Sprintf("%s://%s%s", p.getScheme(req), req.Host, req.URL.RequestURI()))
http.Redirect(rw, req, fmt.Sprintf("%s/auth/login?redirect=%s", p.appBaseUrl, originalRequestURL), http.StatusFound) http.Redirect(rw, req, fmt.Sprintf("%s/auth/login?redirect=%s", p.appBaseUrl, originalRequestURL), http.StatusFound)
return return
} }
@@ -57,3 +57,10 @@ func (p *Badger) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
p.next.ServeHTTP(rw, req) p.next.ServeHTTP(rw, req)
} }
func (p *Badger) getScheme(req *http.Request) string {
if req.TLS != nil {
return "https"
}
return "http"
}