feature-toggles
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -21,2 +21,9 @@ var _toggles = {}; | ||
return toggleValue === true; | ||
}; | ||
exports.middleware = function(request, response, next) { | ||
response.locals.isFeatureEnabled = function(name) { | ||
return exports.isFeatureEnabled(name, request, response); | ||
}; | ||
next(); | ||
}; |
{ | ||
"name": "feature-toggles", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Feature Toggles for Node.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -25,3 +25,3 @@ # feature-toggles | ||
// check if a feature is enabled | ||
if (featureToggles.isFeatureEnabled('foo') { | ||
if (featureToggles.isFeatureEnabled('foo')) { | ||
// do something | ||
@@ -73,3 +73,3 @@ } | ||
app.get('/', function() { | ||
app.get('/', function(request, response) { | ||
if (featureToggles.isFeatureEnabled('foo', request)) { | ||
@@ -85,3 +85,3 @@ // do something | ||
var toggles = { | ||
foo: function(request) { | ||
foo: function() { | ||
var date = new Date(); | ||
@@ -95,3 +95,3 @@ return date.getDate() > 15; | ||
if (featureToggles.isFeatureEnabled('foo', request)) { | ||
if (featureToggles.isFeatureEnabled('foo')) { | ||
// do something | ||
@@ -101,2 +101,27 @@ } | ||
#### Express integration | ||
Use the middleware to easily toggle features per request. | ||
This way a special version of `isFeatureEnabled()` is exposed to all views (res.locals). | ||
Computed toggles will automatically receive the current request and response as arguments. | ||
```javascript | ||
var toggles = { | ||
foo: function(request, response) { | ||
return request.param('enableFoo'); | ||
} | ||
} | ||
``` | ||
```javascript | ||
var application = express(); | ||
application.use(featureToggles.middleware); | ||
``` | ||
```jade | ||
- if (isFeatureEnabled('foo')) | ||
Foo is enabled | ||
``` | ||
### Alternative modules | ||
@@ -103,0 +128,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9047
153
126