Skip to content

Commit

Permalink
Removed explicit static file path declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav Simovski committed Sep 12, 2019
1 parent 7f8f972 commit d64a46f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
24 changes: 9 additions & 15 deletions api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit d64a46f

Please sign in to comment.