Merge pull request #80 from ajayyy/get-ip-fixes

Get IP options
This commit is contained in:
Ajay Ramachandran
2020-05-15 19:16:19 -04:00
committed by GitHub
2 changed files with 14 additions and 3 deletions

View File

@@ -2,5 +2,16 @@ var fs = require('fs');
var config = require('../config.js');
module.exports = function getIP(req) {
return config.behindProxy ? req.headers['x-forwarded-for'] : req.connection.remoteAddress;
}
if (config.behindProxy === true || config.behindProxy === "true") config.behindProxy = "X-Forwarded-For";
switch (config.behindProxy) {
case "X-Forwarded-For":
return req.headers['X-Forwarded-For'];
case "Cloudflare":
return req.headers['CF-Connecting-IP'];
case "X-Real-IP":
return req.headers['X-Real-IP'];
default:
return req.connection.remoteAddress;
}
}