Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/billiegoose/whitelist-ips
Connect/Express middleware for whitelisting by IP addresses.
https://github.com/billiegoose/whitelist-ips
Last synced: 24 days ago
JSON representation
Connect/Express middleware for whitelisting by IP addresses.
- Host: GitHub
- URL: https://github.com/billiegoose/whitelist-ips
- Owner: billiegoose
- License: isc
- Created: 2015-07-26T23:48:17.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-10-21T18:15:11.000Z (about 8 years ago)
- Last Synced: 2024-10-23T00:29:57.850Z (3 months ago)
- Language: CoffeeScript
- Size: 7.81 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# whitelist-ips
Connect/Express middleware for whitelisting by IP addresses.Pretty simple really. Example:
```Javascript
var express = require('express');
var whitelist = require('./index');var app = express();
// Use one of the built-in lists. So far it's just Cloudflare. (https://www.cloudflare.com/ips-v4 and ips-v6)
app.use(whitelist('common/cloudflare'));
// OR
// Pass an array of IP addresses
app.use(whitelist( ['127.0.0.1', '192.168.0.0/24'] ));
// OR
// Pass a filename
app.use(whitelist('whitelist.txt'));app.get('/', function (req, res) {
res.send('Hello '+req.ip+'!');
});
app.use(function (err, req, res, next) {
if (err.name == "WhitelistIpError") {
res.status(403).send('Forbidden');
} else {
res.status(404).send('Not Found');
}
});var server = app.listen(8080);
```Requests that come from addresses outside of the whitelist generate an error
that you can handle with Express's middleware error handling facilities.