mirror of
https://github.com/fosrl/badger.git
synced 2026-03-03 09:16:51 +00:00
Its working!
This commit is contained in:
9
main.go
9
main.go
@@ -39,7 +39,7 @@ 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 {
|
||||||
// No session cookie, redirect to login
|
// No session cookie, redirect to login
|
||||||
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
|
||||||
}
|
}
|
||||||
@@ -62,3 +62,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"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user