diff --git a/lib/web/jade.js b/lib/web/jade.js index a15a6425..02c5d94a 100644 --- a/lib/web/jade.js +++ b/lib/web/jade.js @@ -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 */