feature-toggle-express-middleware
This middleware manages feature toggles. You can switch on/off features using a query parameter. It stores them in a cookie.
const featureToggle = ; // pass a list of allowed features and a prefix representing your applicationconst featureToggleMiddleware = ; app;
featureToggle takes this arguments:
- an array with allowed toggles (a toggle is a string)
- a prefix that is used for the cookie and the query parameters
- [optional] the options for the cookie (see expressjs documentation)
- [optional] a boolean that when true, disable automatic cache control headers
Using the middleware
You can switch a feature on using the addToggles query parameter:
http://www.example.com?myappAddToggles=feature1
You can also enable multiple features:
http://www.example.com?myappAddToggles=feature1,feature2
You can remove one or more feature:
http://www.example.com?myappRemoveToggles=feature1
http://www.example.com?myappRemoveToggles=feature1,feature2
You can use both query parameter to add/remove toggles
http://www.example.com?myappRemoveToggles=feature1&myappAddToggles=feature2
You can switch off all toggles:
http://www.example.com?myappResetToggles=true
allow-feature
This is another middleware that, used together with featureToggle enable/disable a specific endpoint.
const allowFeature = ; const disableWithFeature1 = allowFeature;const enableWithFeature1 = allowFeature; app; app;
Notes
This module is implemented with ES6 feature. Use it with the appropriate node versions. The middleware provides to disable cache (using cache headers), when a feature toggle is enabled.