From 91d81c4367d0fff367eb89dfa6f6e7532dfd9b2d Mon Sep 17 00:00:00 2001 From: calzoneman Date: Wed, 12 Aug 2015 20:00:52 -0700 Subject: [PATCH] Respect X-Forwarded-Proto if it is set --- lib/web/jade.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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 */