From d64a46fac84f23629f4595b21cdb89927db90633 Mon Sep 17 00:00:00 2001 From: Stanislav Simovski Date: Thu, 12 Sep 2019 21:35:44 +0300 Subject: [PATCH] Removed explicit static file path declaration --- Taskfile.yml | 2 +- api/router.go | 24 +++++++++--------------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index 3d5eb8f63..f73c439a7 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -100,7 +100,7 @@ tasks: sh: git rev-parse --abbrev-ref HEAD DIRTY: # We must exclude the package-lock file as npm install can change it! - sh: git diff --exit-code --stat -- . ':(exclude)web/package-lock.json' ':(exclude)web/package.json' + sh: git diff --exit-code --stat -- . ':(exclude)web/package-lock.json' ':(exclude)web/package.json' || true SHA: sh: git log --pretty=format:'%h' -n 1 TIMESTAMP: diff --git a/api/router.go b/api/router.go index 99557affb..54b5bf8a0 100644 --- a/api/router.go +++ b/api/router.go @@ -57,21 +57,20 @@ func Route() *mux.Router { webPath = util.WebHostURL.Path } - r.Use(mux.CORSMethodMiddleware(r), JSONMiddleware) - defer r.HandleFunc(webPath, http.HandlerFunc(servePublic)) + r.Use(mux.CORSMethodMiddleware(r)) - publicAPI := r.PathPrefix(webPath + "api").Subrouter() - - publicAPI.HandleFunc("/auth/login", login).Methods("POST") - publicAPI.HandleFunc("/auth/logout", logout).Methods("POST") - - pingRouter := publicAPI.Path("/ping").Subrouter() + pingRouter := r.Path(webPath + "api/ping").Subrouter() pingRouter.Use(plainTextMiddleware) pingRouter.Methods("GET", "HEAD").HandlerFunc(pongHandler) - authenticatedAPI := r.PathPrefix(webPath + "api").Subrouter() + publicAPIRouter := r.PathPrefix(webPath + "api").Subrouter() + publicAPIRouter.Use(JSONMiddleware) - authenticatedAPI.Use(authentication) + publicAPIRouter.HandleFunc("/auth/login", login).Methods("POST") + publicAPIRouter.HandleFunc("/auth/logout", logout).Methods("POST") + + authenticatedAPI := r.PathPrefix(webPath + "api").Subrouter() + authenticatedAPI.Use(JSONMiddleware, authentication) authenticatedAPI.Path("/ws").HandlerFunc(sockets.Handler).Methods("GET", "HEAD") authenticatedAPI.Path("/info").HandlerFunc(getSystemInfo).Methods("GET", "HEAD") @@ -222,11 +221,6 @@ func debugPrintRoutes(r *mux.Router) { func servePublic(w http.ResponseWriter, r *http.Request) { path := r.URL.Path - if strings.HasPrefix(path, "/api") { - notFoundHandler(w, r) - return - } - webPath := "/" if util.WebHostURL != nil { webPath = util.WebHostURL.RequestURI()