1.1.0 • Published 5 years ago
ip_whitelisting_middleware v1.1.0
This middleware is used to pass a flag for whitelisted ips setted in process.env variable.
(ips) => {
return (req, res, next) => {
const ip = req.get('X-Forwarded-For') || req.ip;
if (!ips) {
ips = '';
}
let whitelistedIps = ips.split(',');
if (whitelistedIps.length > 0) {
whitelistedIps = whitelistedIps.map(ip => ip.trim());
}
req.whitelistedIp = false;
if (ipRangeCheck(String(ip), whitelistedIps)) {
req.whitelistedIp = true;
}
next();
}
};