Skip to content

Commit

Permalink
Merge pull request #22 from Mirantis/use-negroni-recovery
Browse files Browse the repository at this point in the history
Add negroni.Recovery middleware to handle server panic
  • Loading branch information
aateem authored Jan 30, 2017
2 parents 454a03c + 2fdd8b2 commit 5bfdf64
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ func setupRouter(chkr Checker) *httprouter.Router {
return router
}

func addMiddleware(handler http.Handler) http.Handler {
n := negroni.New()
n.Use(negroni.NewLogger())
n.Use(negroni.NewRecovery())
n.UseHandler(handler)
return n
}

func main() {
var endpoint string
var initKubeProxy bool
Expand All @@ -120,11 +128,6 @@ func main() {
panic(err.Error())
}

router := setupRouter(checker)

n := negroni.New()
n.Use(negroni.NewLogger())
n.UseHandler(router)

http.ListenAndServe(endpoint, n)
handler := addMiddleware(setupRouter(checker))
http.ListenAndServe(endpoint, handler)
}

0 comments on commit 5bfdf64

Please sign in to comment.