From 6ed44db56b5b76701b80b7b68e8d6cea75298603 Mon Sep 17 00:00:00 2001 From: Adhityaa Chandrasekar Date: Wed, 8 Aug 2018 12:16:27 +0530 Subject: [PATCH] everywhere: allow subdir-ed origin setups Closes https://gitlab.com/commento/commento-ce/issues/61 --- api/router.go | 5 +++++ api/router_static.go | 19 ++++++++++++++----- frontend/dashboard.html | 4 ++-- frontend/footer.html | 6 +++--- frontend/forgot.html | 7 ++++--- frontend/js/auth-common.js | 2 +- frontend/js/dashboard-danger.js | 2 +- frontend/js/login.js | 2 +- frontend/js/logout.js | 2 +- frontend/js/reset.js | 2 +- frontend/js/self.js | 4 ++-- frontend/js/signup.js | 4 ++-- frontend/login.html | 10 +++++----- frontend/reset-password.html | 7 +++---- frontend/signup.html | 8 ++++---- 15 files changed, 49 insertions(+), 35 deletions(-) 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 @@