r.Route before r.Use

This commit is contained in:
AJ ONeal 2020-11-19 22:08:56 +00:00 committed by AJ ONeal
parent 7dff34e6e3
commit 6810c6f86d
2 changed files with 91 additions and 84 deletions

View File

@ -29,11 +29,14 @@ var presenters = make(chan *Challenge)
var cleanups = make(chan *Challenge) var cleanups = make(chan *Challenge)
func RouteStatic(r chi.Router) chi.Router { func RouteStatic(r chi.Router) chi.Router {
r.Route("/", func(r chi.Router) {
r.Use(middleware.Logger) r.Use(middleware.Logger)
r.Use(middleware.Timeout(15 * time.Second)) r.Use(middleware.Timeout(15 * time.Second))
r.Use(middleware.Recoverer) r.Use(middleware.Recoverer)
r.Get("/.well-known/acme-challenge/{token}", getACMEChallenges) r.Get("/.well-known/acme-challenge/{token}", getACMEChallenges)
})
return r return r
} }

View File

@ -29,15 +29,18 @@ func RouteAdmin(authURL string, r chi.Router) {
authorizer = NewAuthorizer(authURL) authorizer = NewAuthorizer(authURL)
r.Route("/", func(r chi.Router) {
r.Use(middleware.Logger) r.Use(middleware.Logger)
//r.Use(middleware.Timeout(120 * time.Second)) //r.Use(middleware.Timeout(120 * time.Second))
r.Use(middleware.Recoverer) r.Use(middleware.Recoverer)
/*
r.Use(func(next http.Handler) http.Handler { r.Use(func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
next.ServeHTTP(w, r) next.ServeHTTP(w, r)
}) })
}) })
*/
r.Mount("/ws", http.HandlerFunc(upgradeWebsocket)) r.Mount("/ws", http.HandlerFunc(upgradeWebsocket))
@ -114,6 +117,7 @@ func RouteAdmin(authURL string, r chi.Router) {
fmt.Println("Request Path:", r.URL.Path) fmt.Println("Request Path:", r.URL.Path)
adminUI.ServeHTTP(w, r) adminUI.ServeHTTP(w, r)
}) })
})
} }
var apiNotFoundContent = []byte("{ \"error\": \"not found\" }\n") var apiNotFoundContent = []byte("{ \"error\": \"not found\" }\n")