Skip to content

skellertor/gate-keep

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Express middleware for white/black listing IP Addresses

Getting Started


  • In the root of your express app create a .yaml file (You can name it whatever you want)
  • Define two sections
    • whitelist
    • blacklist
      • Look at priviledge.yaml in root of gate-keep for an example
  • List IP Addresses in sequence notation under each section

Example

var express = require('express'),
    app = express(),
    path = require('path');
    
var gatekeep = require('gate-keep');
gatekeep.setprivilege(path.join(__dirname, 'privilege.yaml')); //pass absolute path to .yaml allowed/blocked file

app.use(gatekeep.white.privilege); //Allows only the specified IP Address in privilege.yaml `whitelist` section
// Other configurations include
// app.use(gatekeep.black.privilege); Allows access to all IP Addresses except those listed in privilege.yaml `blacklist` section

/****************
 * Other stuff **
 ****************/
 
// gate-keep passes a `err` to next() when the IP is restricted so you 
// need to define an error handler to catch it
app.use(function(err, req, res, next){
    res.status(403);
    res.send('Denied');
});

app.listen(3000);

About

IP address white/black list express middleware

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published