diff --git a/main.go b/main.go index c9e9ab3..1f8390c 100644 --- a/main.go +++ b/main.go @@ -133,30 +133,20 @@ func main() { // Setup Routing router := mux.NewRouter() - mainRouter := mux.NewRouter().PathPrefix("").Subrouter() + mainRouter := mux.NewRouter().PathPrefix("/").Subrouter() apiRouter := mux.NewRouter().PathPrefix("/api").Subrouter() // Main Routes - index := mainRouter.Path("/").Subrouter() - index.Methods(http.MethodGet).Path("/").HandlerFunc(summaryHandler.Index) + mainRouter.Path("/").Methods(http.MethodGet).HandlerFunc(summaryHandler.Index) // API Routes - heartbeats := apiRouter.Path("/heartbeat").Subrouter() - heartbeats.Methods(http.MethodPost).HandlerFunc(heartbeatHandler.Post) + apiRouter.Path("/heartbeat").Methods(http.MethodPost).HandlerFunc(heartbeatHandler.Post) + apiRouter.Path("/summary").Methods(http.MethodGet).HandlerFunc(summaryHandler.Get) // Static Routes router.PathPrefix("/assets").Handler(negroni.Classic().With(negroni.Wrap(http.FileServer(http.Dir("./static"))))) - aggreagations := apiRouter.Path("/summary").Subrouter() - aggreagations.Methods(http.MethodGet).HandlerFunc(summaryHandler.Get) - // Sub-Routes Setup - router.PathPrefix("/").Handler(negroni.Classic(). - With(negroni.HandlerFunc(basicAuthMiddleware.Handle), - negroni.HandlerFunc(authenticateMiddleware.Handle), - negroni.Wrap(mainRouter), - )) - router.PathPrefix("/api").Handler(negroni.Classic(). With(corsMiddleware). With( @@ -164,6 +154,12 @@ func main() { negroni.Wrap(apiRouter), )) + router.PathPrefix("/").Handler(negroni.Classic().With( + negroni.HandlerFunc(basicAuthMiddleware.Handle), + negroni.HandlerFunc(authenticateMiddleware.Handle), + negroni.Wrap(mainRouter), + )) + // Listen HTTP portString := config.Addr + ":" + strconv.Itoa(config.Port) s := &http.Server{