Add a way to extend the handlers and add custom stuff
This commit is contained in:
2
api.go
2
api.go
@@ -42,7 +42,7 @@ func main() {
|
|||||||
sch.Start()
|
sch.Start()
|
||||||
|
|
||||||
handlers.Bootstrap(core, e)
|
handlers.Bootstrap(core, e)
|
||||||
handlers.Register()
|
handlers.Register(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func initStorage() storage.StorageApi {
|
func initStorage() storage.StorageApi {
|
||||||
|
|||||||
@@ -25,12 +25,14 @@ var core pwd.PWDApi
|
|||||||
var e event.EventApi
|
var e event.EventApi
|
||||||
var ws *socketio.Server
|
var ws *socketio.Server
|
||||||
|
|
||||||
|
type HandlerExtender func(h *mux.Router)
|
||||||
|
|
||||||
func Bootstrap(c pwd.PWDApi, ev event.EventApi) {
|
func Bootstrap(c pwd.PWDApi, ev event.EventApi) {
|
||||||
core = c
|
core = c
|
||||||
e = ev
|
e = ev
|
||||||
}
|
}
|
||||||
|
|
||||||
func Register() {
|
func Register(extend HandlerExtender) {
|
||||||
|
|
||||||
bypassCaptcha := len(os.Getenv("GOOGLE_RECAPTCHA_DISABLED")) > 0
|
bypassCaptcha := len(os.Getenv("GOOGLE_RECAPTCHA_DISABLED")) > 0
|
||||||
|
|
||||||
@@ -91,6 +93,10 @@ func Register() {
|
|||||||
|
|
||||||
corsRouter.HandleFunc("/", NewSession).Methods("POST")
|
corsRouter.HandleFunc("/", NewSession).Methods("POST")
|
||||||
|
|
||||||
|
if extend != nil {
|
||||||
|
extend(corsRouter)
|
||||||
|
}
|
||||||
|
|
||||||
n := negroni.Classic()
|
n := negroni.Classic()
|
||||||
r.PathPrefix("/").Handler(negroni.New(negroni.Wrap(corsHandler(corsRouter))))
|
r.PathPrefix("/").Handler(negroni.New(negroni.Wrap(corsHandler(corsRouter))))
|
||||||
n.UseHandler(r)
|
n.UseHandler(r)
|
||||||
|
|||||||
Reference in New Issue
Block a user