ip_whitelisting_middleware
v1.1.0
Published
This will allow to whitelist ips
Downloads
15
Readme
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();
}
};