Feature flipping!
TODO: Fill out this long description.
npm install --save feature-flipper
const Flipper = require('feature-flipper');
const flip = new Flipper();
// Lets add a feature
flip.set('somefeature', false);
// Use the set method to change the status of a feature
flip.set('somefeature', true);
// To check if a feature is enabled
console.log( flip.isEnabled('somefeature') ); // true
// To flip the status of the feature
flip.flip('somefeature');
console.log( flip.isEnabled('somefeature') ); // false
// To remove the feature
flip.remove('somefeature');
// If you have your feature set in a seperate json object / file you can load them in
const featureSet = {
somefeature: true,
someOtherFeature: false
};
flip.load(featureSet);
console.log( flip.isEnabled('someOtherFeature') ); // false
TODO: Fill out API specification.
This module can be used to enable/disable endpoints in your restify/express like http server with a middleware like the following.
function flipMW(feature) {
return function(req, res, next) {
if(flip.isEnabled(feature)) {
return next();
} else {
return res.send(403);
}
}
}
server.get('/somefeature', [
flipMW('somefeature'),
(req, res, next) => {
res.send('somefeature endpoint');
return next();
}
]);
PRs accepted.
MIT © 2017 Rolf Koenders