-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
29 lines (26 loc) · 819 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
var featureToggles = {
_toggles: {},
load: function(toggles) {
this._toggles = toggles;
},
isFeatureEnabled: function(featureName) {
var toggle = this._toggles[featureName];
if (typeof toggle == 'function') {
try {
var toggleArguments = Array.prototype.slice.call(arguments, 1);
toggle = toggle.apply(this, toggleArguments);
}
catch (error) {
return false;
}
}
return toggle === true;
},
middleware: function(request, response, next) {
response.locals.isFeatureEnabled = function(featureName) {
return featureToggles.isFeatureEnabled(featureName, request, response);
};
next();
}
};
module.exports = featureToggles;