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:
parent
fd1f749599
commit
c7556fa9a5
24
main.go
24
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{
|
||||
|
Loading…
Reference in New Issue
Block a user