Respect X-Forwarded-Proto if it is set

This commit is contained in:
calzoneman 2015-08-12 20:00:52 -07:00
parent a405c2c5fa
commit 91d81c4367
1 changed files with 13 additions and 1 deletions

View File

@ -16,7 +16,7 @@ function merge(locals, res) {
loginDomain: Config.get("https.enabled") ? Config.get("https.full-address")
: Config.get("http.full-address"),
csrfToken: res.req.csrfToken(),
baseUrl: res.req.protocol + "://" + res.req.header("host")
baseUrl: getBaseUrl(res)
};
if (typeof locals !== "object") {
return _locals;
@ -27,6 +27,18 @@ function merge(locals, res) {
return _locals;
}
function getBaseUrl(res) {
var req = res.req;
var proto;
if (["http", "https"].indexOf(req.header("x-forwarded-proto")) >= 0) {
proto = req.header("x-forwarded-proto");
} else {
proto = req.protocol;
}
return proto + "://" + req.header("host");
}
/**
* Renders and serves a jade template
*/