diff --git a/api/router.go b/api/router.go index 940c839..f270cd4 100644 --- a/api/router.go +++ b/api/router.go @@ -10,6 +10,11 @@ import ( func routesServe() error { router := mux.NewRouter() + subdir := pathStrip(os.Getenv("ORIGIN")) + if subdir != "" { + router = router.PathPrefix(subdir).Subrouter() + } + if err := apiRouterInit(router); err != nil { return err } diff --git a/api/router_static.go b/api/router_static.go index 982b9d4..5f0da5a 100644 --- a/api/router_static.go +++ b/api/router_static.go @@ -13,7 +13,7 @@ import ( ) func redirectLogin(w http.ResponseWriter, r *http.Request) { - http.Redirect(w, r, "/login", 301) + http.Redirect(w, r, os.Getenv("ORIGIN")+"/login", 301) } type staticAssetPlugs struct { @@ -21,6 +21,7 @@ type staticAssetPlugs struct { } type staticHtmlPlugs struct { + Origin string CdnPrefix string Footer template.HTML } @@ -56,9 +57,11 @@ func staticRouterInit(router *mux.Router) error { gzip := (os.Getenv("GZIP_STATIC") == "true") - asset[p] = []byte(prefix + string(contents)) + subdir := pathStrip(os.Getenv("ORIGIN")) + + asset[subdir+p] = []byte(prefix + string(contents)) if gzip { - gzippedAsset[p], err = gzipStatic(asset[p]) + gzippedAsset[subdir+p], err = gzipStatic(asset[subdir+p]) if err != nil { logger.Errorf("error gzipping %s: %v", p, err) return err @@ -115,9 +118,15 @@ func staticRouterInit(router *mux.Router) error { } var buf bytes.Buffer - t.Execute(&buf, &staticHtmlPlugs{CdnPrefix: os.Getenv("CDN_PREFIX"), Footer: template.HTML(string(footer))}) + t.Execute(&buf, &staticHtmlPlugs{ + Origin: os.Getenv("ORIGIN"), + CdnPrefix: os.Getenv("CDN_PREFIX"), + Footer: template.HTML(string(footer)), + }) - html[page] = buf.String() + subdir := pathStrip(os.Getenv("ORIGIN")) + + html[subdir+page] = buf.String() } for _, page := range pages { diff --git a/frontend/dashboard.html b/frontend/dashboard.html index 7520304..2f6c2a6 100644 --- a/frontend/dashboard.html +++ b/frontend/dashboard.html @@ -12,9 +12,9 @@ diff --git a/frontend/footer.html b/frontend/footer.html index d6b91bb..f0bd3ad 100644 --- a/frontend/footer.html +++ b/frontend/footer.html @@ -3,9 +3,9 @@