Centralize x-forwarded-proto handling; fixes #542

This commit is contained in:
calzoneman 2015-12-12 16:25:59 -08:00
parent 1f9e396e05
commit 27af66075e
3 changed files with 13 additions and 9 deletions

View file

@ -22,9 +22,19 @@ export default function initialize(app, webConfig) {
return req.ip;
}
function getForwardedProto(req) {
const xForwardedProto = req.header('x-forwarded-proto');
if (xForwardedProto && xForwardedProto.match(/^https?$/)) {
return xForwardedProto;
} else {
return req.protocol;
}
}
app.use((req, res, next) => {
if (isTrustedProxy(req.ip)) {
req.realIP = getForwardedIP(req);
req.realProtocol = getForwardedProto(req);
}
next();