1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

Fix API endpoints.

This commit is contained in:
Ferdinand Mütsch 2020-02-21 12:41:29 +01:00
parent fd1f749599
commit c7556fa9a5

24
main.go
View File

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