Skip to content

Commit

Permalink
pkg/dashboard: setup basePath as a path prefix in routing (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdecaf authored and Robert Brennan committed Oct 2, 2019
1 parent 434b1f6 commit 150b812
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/dashboard/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"encoding/json"
"html/template"
"net/http"
"path"
"strings"

conf "github.com/fairwindsops/polaris/pkg/config"
Expand Down Expand Up @@ -137,7 +138,7 @@ func writeTemplate(tmpl *template.Template, data *templateData, w http.ResponseW

// GetRouter returns a mux router serving all routes necessary for the dashboard
func GetRouter(c conf.Configuration, auditPath string, port int, basePath string, auditData *validator.AuditData) *mux.Router {
router := mux.NewRouter()
router := mux.NewRouter().PathPrefix(basePath).Subrouter()
router.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("OK"))
})
Expand Down Expand Up @@ -177,9 +178,9 @@ func GetRouter(c conf.Configuration, auditPath string, port int, basePath string
DetailsHandler(w, r, category, basePath)
})
fileServer := http.FileServer(GetAssetBox())
router.PathPrefix("/static/").Handler(http.StripPrefix("/static/", fileServer))
router.PathPrefix("/static/").Handler(http.StripPrefix(path.Join(basePath, "/static/"), fileServer))
router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
if r.URL.Path != "/" && r.URL.Path != basePath {
http.NotFound(w, r)
return
}
Expand Down

0 comments on commit 150b812

Please sign in to comment.