Centralize x-forwarded-proto handling; fixes #542
This commit is contained in:
parent
1f9e396e05
commit
27af66075e
3 changed files with 13 additions and 9 deletions
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue