Skip to content

Commit

Permalink
Add a way to extend the handlers and add custom stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
xetorthio committed Sep 22, 2017
1 parent ff905a0 commit 98735a5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion api.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func main() {
sch.Start()

handlers.Bootstrap(core, e)
handlers.Register()
handlers.Register(nil)
}

func initStorage() storage.StorageApi {
Expand Down
8 changes: 7 additions & 1 deletion handlers/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ var core pwd.PWDApi
var e event.EventApi
var ws *socketio.Server

type HandlerExtender func(h *mux.Router)

func Bootstrap(c pwd.PWDApi, ev event.EventApi) {
core = c
e = ev
}

func Register() {
func Register(extend HandlerExtender) {

bypassCaptcha := len(os.Getenv("GOOGLE_RECAPTCHA_DISABLED")) > 0

Expand Down Expand Up @@ -91,6 +93,10 @@ func Register() {

corsRouter.HandleFunc("/", NewSession).Methods("POST")

if extend != nil {
extend(corsRouter)
}

n := negroni.Classic()
r.PathPrefix("/").Handler(negroni.New(negroni.Wrap(corsHandler(corsRouter))))
n.UseHandler(r)
Expand Down

0 comments on commit 98735a5

Please sign in to comment.