forked from ory/kratos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
redir.go
36 lines (27 loc) · 920 Bytes
/
redir.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package x
import (
"net/http"
"path/filepath"
"github.com/julienschmidt/httprouter"
"github.com/ory/kratos/driver/config"
)
func RedirectToAdminRoute(reg config.Provider) httprouter.Handle {
return func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
admin := reg.Config(r.Context()).SelfAdminURL()
dest := *r.URL
dest.Host = admin.Host
dest.Scheme = admin.Scheme
dest.Path = filepath.Join(admin.Path + dest.Path)
http.Redirect(w, r, dest.String(), http.StatusTemporaryRedirect)
}
}
func RedirectToPublicRoute(reg config.Provider) httprouter.Handle {
return func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
public := reg.Config(r.Context()).SelfPublicURL(r)
dest := *r.URL
dest.Host = public.Host
dest.Scheme = public.Scheme
dest.Path = filepath.Join(public.Path + dest.Path)
http.Redirect(w, r, dest.String(), http.StatusTemporaryRedirect)
}
}