everywhere: allow subdir-ed origin setups

Closes https://gitlab.com/commento/commento-ce/issues/61
This commit is contained in:
Adhityaa Chandrasekar 2018-08-08 12:16:27 +05:30
parent ee324c1f28
commit 6ed44db56b
15 changed files with 49 additions and 35 deletions

View File

@ -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
}

View File

@ -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 {

View File

@ -12,9 +12,9 @@
</head>
<div id="navbar" class="navbar">
<a href="/" class="navbar-item navbar-logo-text"><img src="[[[.CdnPrefix]]]/images/logo.svg" class="navbar-logo">Commento</a>
<a href="[[[.Origin]]]/" class="navbar-item navbar-logo-text"><img src="[[[.CdnPrefix]]]/images/logo.svg" class="navbar-logo">Commento</a>
<div class="navbar-item">
<a href="/logout" class="navbar-item">Logout</a>
<a href="[[[.Origin]]]/logout" class="navbar-item">Logout</a>
<div class="float-right"><b><div id="owner-name"></div></b></div>
</div>
</div>

View File

@ -3,9 +3,9 @@
<div class="links">
<div class="link-group">
<div class="header">Your Installation</div>
<a class="link" href="/login">Login</a>
<a class="link" href="/signup">Signup</a>
<a class="link" href="/dashboard">Dashboard</a>
<a class="link" href="[[[.Origin]]]/login">Login</a>
<a class="link" href="[[[.Origin]]]/signup">Signup</a>
<a class="link" href="[[[.Origin]]]/dashboard">Dashboard</a>
</div>
<div class="link-group">
<div class="header">Documentation</div>

View File

@ -9,9 +9,9 @@
</head>
<div class="navbar">
<a href="/" class="navbar-item navbar-logo-text"><img src="[[[.CdnPrefix]]]/images/logo.svg" class="navbar-logo">Commento</a>
<a href="/login" class="navbar-item">Login</a>
<a href="/signup" class="navbar-item">Signup</a>
<a href="[[[.Origin]]]/" class="navbar-item navbar-logo-text"><img src="[[[.CdnPrefix]]]/images/logo.svg" class="navbar-logo">Commento</a>
<a href="[[[.Origin]]]/login" class="navbar-item">Login</a>
<a href="[[[.Origin]]]/signup" class="navbar-item">Signup</a>
</div>
<div class="auth-form-container">
@ -26,6 +26,7 @@
<div class="err" id="err"></div>
<div class="msg" id="msg"></div>
<button id="reset-button" class="button" onclick="sendResetHex()">Send Reset Password Link</button>
<a class="link" href="[[[.Origin]]]/login">Suddenly remembered your password? Login.</a>
</div>
</div>

View File

@ -5,7 +5,7 @@
// cookie is deleted.
global.loggedInRedirect = function() {
if (global.cookieGet("commentoOwnerToken") !== undefined)
document.location = "/dashboard";
document.location = global.commentoOrigin + "/dashboard";
}

View File

@ -13,7 +13,7 @@
domainDelete(data.domains[data.cd].domain, function(success) {
if (success)
document.location = '/dashboard';
document.location = global.commentoOrigin + '/dashboard';
});
}

View File

@ -66,7 +66,7 @@
}
global.cookieSet("commentoOwnerToken", resp.ownerToken);
document.location = "/dashboard";
document.location = global.commentoOrigin + "/dashboard";
});
};

View File

@ -2,7 +2,7 @@
global.logout = function() {
global.cookieSet("commentoOwnerToken", "");
document.location = "/login";
document.location = global.commentoOrigin + "/login";
}
} (window, document));

View File

@ -30,7 +30,7 @@
return
}
document.location = "/login?changed=true";
document.location = global.commentoOrigin + "/login?changed=true";
});
}

View File

@ -7,14 +7,14 @@
};
if (json.ownerToken === undefined) {
document.location = "/login";
document.location = global.commentoOrigin + "/login";
return;
}
global.post(global.commentoOrigin + "/api/owner/self", json, function(resp) {
if (!resp.success || !resp.loggedIn) {
global.cookieDelete("commentoOwnerToken");
document.location = "/login";
document.location = global.commentoOrigin + "/login";
return;
}

View File

@ -34,9 +34,9 @@
}
if (resp.confirmEmail)
document.location = "/confirm-email";
document.location = global.commentoOrigin + "/confirm-email";
else
document.location = "/login?signedUp=true";
document.location = global.commentoOrigin + "/login?signedUp=true";
});
};

View File

@ -9,9 +9,9 @@
</head>
<div class="navbar">
<a href="/" class="navbar-item navbar-logo-text"><img src="[[[.CdnPrefix]]]/images/logo.svg" class="navbar-logo">Commento</a>
<a href="/login" class="navbar-item"><b>Login</b></a>
<a href="/signup" class="navbar-item">Signup</a>
<a href="[[[.Origin]]]/" class="navbar-item navbar-logo-text"><img src="[[[.CdnPrefix]]]/images/logo.svg" class="navbar-logo">Commento</a>
<a href="[[[.Origin]]]/login" class="navbar-item"><b>Login</b></a>
<a href="[[[.Origin]]]/signup" class="navbar-item">Signup</a>
</div>
<script>
@ -43,8 +43,8 @@
<button id="button" class="button" onclick="window.login()">Login</button>
<a class="link" href="/reset">Trouble logging in? Reset your password.</a>
<a class="link" href="/signup">Don't have an account yet? Sign up.</a>
<a class="link" href="[[[.Origin]]]/forgot">Trouble logging in? Reset your password.</a>
<a class="link" href="[[[.Origin]]]/signup">Don't have an account yet? Sign up.</a>
</div>
</div>

View File

@ -9,9 +9,9 @@
</head>
<div class="navbar">
<a href="/" class="navbar-item navbar-logo-text"><img src="[[[.CdnPrefix]]]/images/logo.svg" class="navbar-logo">Commento</a>
<a href="/login" class="navbar-item">Login</a>
<a href="/signup" class="navbar-item">Signup</a>
<a href="[[[.Origin]]]/" class="navbar-item navbar-logo-text"><img src="[[[.CdnPrefix]]]/images/logo.svg" class="navbar-logo">Commento</a>
<a href="[[[.Origin]]]/login" class="navbar-item">Login</a>
<a href="[[[.Origin]]]/signup" class="navbar-item">Signup</a>
</div>
<div class="auth-form-container">
@ -33,7 +33,6 @@
<div class="err" id="err"></div>
<div class="msg" id="msg"></div>
<button id="reset-button" class="button" onclick="resetPassword()">Reset Password</button>
<a class="link" href="/login">Suddenly remembered your password? Login.</a>
</div>
</div>

View File

@ -9,9 +9,9 @@
</head>
<div class="navbar">
<a href="/" class="navbar-item navbar-logo-text"><img src="[[[.CdnPrefix]]]/images/logo.svg" class="navbar-logo">Commento</a>
<a href="/login" class="navbar-item">Login</a>
<a href="/signup" class="navbar-item"><b>Signup</b></a>
<a href="[[[.Origin]]]/" class="navbar-item navbar-logo-text"><img src="[[[.CdnPrefix]]]/images/logo.svg" class="navbar-logo">Commento</a>
<a href="[[[.Origin]]]/login" class="navbar-item">Login</a>
<a href="[[[.Origin]]]/signup" class="navbar-item"><b>Signup</b></a>
</div>
<script>
@ -56,7 +56,7 @@
<button id="signup-button" class="button" onclick="window.signup()">Sign up</button>
<a class="link" href="/login">Already have an account? Login instead.</a>
<a class="link" href="[[[.Origin]]]/login">Already have an account? Login instead.</a>
</div>
</div>