Last active
June 10, 2019 20:47
-
-
Save asaschachar/57a597fa8b93e1e5a290b1ab86e8c839 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 express = require('express'); | |
const app = express(); | |
const HOST = process.env.HOST || '0.0.0.0'; | |
const PORT = process.env.PORT || 8080; | |
const optimizelyExpress = require('@optimizely/express'); | |
const optimizely = optimizelyExpress.initialize({ | |
sdkKey: '<Your_SDK_Key>', | |
datafileOptions: { | |
autoUpdate: true, // Indicates feature flags will be auto-updated based on UI changes | |
updateInterval: 1*1000 // 1 second in milliseconds | |
}, | |
logLevel: 'info', // Controls console logging. Can be 'debug', 'info', 'warn', or 'error' | |
}); | |
app.use(optimizely.middleware); | |
app.get('/', function(req, res, next) { | |
const isEnabled = req.optimizely.client.isFeatureEnabled( | |
'hello_world', // Feature key connecting feature to UI | |
'user123', // String ID used for random percentage-based rollout | |
{ | |
customerId: 123, // Attributes used for targeted audience-based rollout | |
isVip: true, | |
} | |
); | |
res.send('Optimizely Express Example: ' + (isEnabled ? 'You got the hello world feature!' : 'Feature off.')) | |
}); | |
app.listen(PORT, HOST); | |
console.log(`Example App Running on http://${HOST}:${PORT}`); | |
module.exports = app; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment