UNPKG

ip-restrictor

Version:

Easily allow or block internal IPs in Node.js and Express apps. A simple middleware for IP filtering and network security.

10 lines (7 loc) 301 B
const getClientIP = require("./getClientIP"); const allowOnly = (allowedIPs) => (req, res, next) => { const clientIP = getClientIP(req); if (allowedIPs.includes(clientIP)) return next(); res.status(403).send("Forbidden: Your IP is not allowed."); }; module.exports = allowOnly;