forked from keratin/authn-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouting.go
55 lines (44 loc) · 1.71 KB
/
routing.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"net/http"
"os"
gorilla "github.com/gorilla/handlers"
"github.com/gorilla/mux"
"github.com/keratin/authn-server/api"
"github.com/keratin/authn-server/api/accounts"
"github.com/keratin/authn-server/api/meta"
"github.com/keratin/authn-server/api/passwords"
"github.com/keratin/authn-server/api/sessions"
"github.com/keratin/authn-server/lib/route"
"github.com/keratin/authn-server/ops"
)
func router(app *api.App) http.Handler {
r := mux.NewRouter()
route.Attach(r, app.Config.MountedPath, meta.Routes(app)...)
route.Attach(r, app.Config.MountedPath, accounts.Routes(app)...)
route.Attach(r, app.Config.MountedPath, sessions.Routes(app)...)
route.Attach(r, app.Config.MountedPath, passwords.Routes(app)...)
return wrapRouter(r, app)
}
func publicRouter(app *api.App) http.Handler {
r := mux.NewRouter()
route.Attach(r, app.Config.MountedPath, meta.PublicRoutes(app)...)
route.Attach(r, app.Config.MountedPath, accounts.PublicRoutes(app)...)
route.Attach(r, app.Config.MountedPath, sessions.PublicRoutes(app)...)
route.Attach(r, app.Config.MountedPath, passwords.PublicRoutes(app)...)
return wrapRouter(r, app)
}
func wrapRouter(r *mux.Router, app *api.App) http.Handler {
stack := gorilla.CombinedLoggingHandler(os.Stdout, r)
stack = api.Session(app)(stack)
stack = gorilla.CORS(
gorilla.AllowedMethods([]string{"GET", "POST", "PUT", "PATCH", "DELETE"}),
gorilla.AllowCredentials(),
gorilla.AllowedOrigins([]string{}), // see: https://github.com/gorilla/handlers/issues/117
gorilla.AllowedOriginValidator(api.OriginValidator(app.Config.ApplicationDomains)),
)(stack)
if app.Config.Proxied {
stack = gorilla.ProxyHeaders(stack)
}
return ops.PanicHandler(app.Reporter, stack)
}