move getIP function to its own module

This commit is contained in:
Mystikfluu
2022-07-31 11:49:11 +02:00
parent 47654513ba
commit 76f1522bf6
4 changed files with 17 additions and 13 deletions
+12
View File
@@ -0,0 +1,12 @@
/**
* gets ip of a request
* @param {request} req
* @returns ip of the given request, after taking preferred headers into account
*/
function getIP(req) {
let ip = req.socket.remoteAddress;
if(req.headers[config.preferred_ip_header] != undefined && ip == config.only_prefer_when_ip)ip = req.headers[config.preferred_ip_header]
return ip
}
module.exports = getIP