Improve proto recognition

This commit is contained in:
Mikołaj Pich 2022-11-24 20:44:09 +01:00
parent 1dba36bc62
commit f1cc110ef4

View file

@ -1,4 +1,9 @@
module.exports = function(req) { module.exports = function(req) {
let proto = req.connection.encrypted || process.env.SSL === 'true' ? 'https' : 'http'; const isConnectionEncrypted = req.connection.encrypted;
const isSslEnvSet = process.env.SSL === 'true';
const isHeaderSsl = req.header('X-Forwaded-Proto') === 'https';
const proto = isConnectionEncrypted || isSslEnvSet || isHeaderSsl ? 'https' : 'http';
return proto.split(/\s*,\s*/)[0]; return proto.split(/\s*,\s*/)[0];
}; };