@mathdoy/toggle-restify
v1.1.2
Published
Toggle feature, a feature flag library for your restify backend
Downloads
3
Maintainers
Readme
Installation
$ npm install --save @mathdoy/toggle @mathdoy/toggle-restify
import restify from "restify";
import { createToggle } from "@mathdoy/toggle";
import toggleRestifyMiddleware from "@mathdoy/toggle-restify";
const toggle = createToggle({
prefix: "X-FEAT-",
features: {
food: false,
},
});
// or use default
// const toggle = createToggle();
// You can manually send `x-feat-food: true` header to overwrite the config and test your feature
const hello = (req, res, next) => {
const response = {
reqToggleFeatures: req.toggle.features,
hello: "hello handler",
name: req.params.name,
isFooEnabled: req.toggle.isEnabled("foo"),
isFoodEnabled: req.toggle.isEnabled("food"),
};
res.send(response);
next();
};
const server = restify.createServer();
server.use(toggleRestifyMiddleware(toggle));
server.get("/hello/:name", hello);
server.head("/hello/:name", hello);
server.listen(8080, function() {
console.log("%s listening at %s", server.name, server.url); // eslint-disable-line no-console
});
For more information on toggle
For more information on toggle see toggle
Using it with react
$ npm install --save @mathdoy/toggle @mathdoy/toggle-react
See more information for toggle-react
License
Toggle is licensed under the MIT License.