g4js-firewall
v0.1.2
Published
Simple pattern based firewall that supports roles and HTTP methods.
Downloads
34
Maintainers
Readme
g4js-firewall
Simple pattern based firewall that supports roles and HTTP methods.
Install
$ npm install g4js-firewall
Usage
Require the module:
var Firewall = require('g4js-firewall').Firewall;
Add some rules:
var firewall = new Firewall();
// admin path restricted to admin role with all methods allowed
firewall.addRule('^/admin', 'admin', '*');
// admin path restricted to admin role with all methods allowed
firewall.addRule('^/orders', ['user','admin'], ['GET','PUT','POST']);
// signup path restricted to readonly role using POST method
firewall.addRule('^/signup', 'readonly', 'POST');
// shop path restricted to readonly role using GET method
firewall.addRule('^/shop', 'readonly', 'GET');
Run some checks:
// returns matching rule if match found
var matchingRule = firewall.check('/admin', ['admin'], 'GET');
// returns undefined if no matching rules found
var noBueno = firewall.check('/admin', 'hog_rider', 'GET');
// express middleware coming soon...
License
Contribute
Pull Requests always welcome, as well as any feedback or issues. Made with OSS <3 and brought to you by #teamgorgeous.