Created
March 21, 2019 16:30
-
-
Save bwll/264b0a1ceb1a27adeede694795a6d78c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const optimizely = require('@optimizely/optimizely-sdk'); | |
// const defaultLogger = require('@optimizely/optimizely-sdk/lib/plugins/logger'); | |
const rp = require('request-promise'); | |
require('dotenv').config(); | |
module.exports = async (req, res, next) => { | |
try { | |
const datafile = await rp({ | |
uri: `https://cdn.optimizely.com/json/${process.env.OPTIMIZELY_FS_PROJECT_ID}.json`, | |
json: true, | |
}); | |
const optimizelyClient = optimizely.createInstance({ | |
datafile, | |
logLevel: 2, | |
}); | |
const featureKey = 'some_feature'; | |
const enabled = optimizelyClient.isFeatureEnabled(featureKey, 'test'); | |
res.locals.features = res.locals.features || {}; | |
res.locals.features = { | |
[featureKey]: enabled, | |
}; | |
next(); | |
} catch (err) { | |
next(err); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment