Our SDK uses the standard node http(s) request library, which unfortunately does not automatically pull in environment-defined proxy settings. I think the current options are:
Use global-agent to set the proxy settings for the http library so that requests from http use your proxy.
npm install --save global-agent
- Before you use the Optimizely SDK:
require('global-agent/bootstrap');
global.GLOBAL_AGENT.HTTP_PROXY = 'http://yourproxy:8080';
Note: replace yourproxy:8080
with the settings of your actual proxy. I think this is the best option, but it's difficult for me to verify that it will work in your environment. If this doesn't work you can try the next option.
Use the urlTemplate option to change where the SDK requests the datafile from to go through your proxy. In the example below if yourproxy:8080 was where your proxy was defined then you could configure your proxy to forward the request for say yourproxy:8080/http://cdn.optimizely.com/datafiles/%s.json to cdn.optimizely.com/datafiles/VXDcKZYzfzTAJDkFtJrHNi.json. Documentation on the urlTemplate option is here.
const client = createInstance({
sdkKey: 'VXDcKZYzfzTAJDkFtJrHNi',
datafileOptions: {
autoUpdate: true,
updateInterval: 60000,
urlTemplate: 'yourproxy:8080/http://cdn.optimizely.com/datafiles/%s.json',
},
});
await client.onReady();
This option likely requires settings to change on your proxy to forward the request properly. Let me know if this option makes sense.
If the above options don't work, an alternative is to not use our out-of-the-box datafile polling mechanism and instead fetch and instantiate the Optimizely client with your own request library, which you can manually configure to point to your proxy:
const request = require('request-promise');
const DATAFILE_URL = "https://cdn.optimizely.com/datafiles/Ly8FQj6vSaDcZUjySoWnWz.json";
const datafile = await request({
uri: DATAFILE_URL,
json: true,
proxy: 'http://yourproxy:8080'
});
const optimizelyClient = optimizely.createInstance({
datafile
});
The downside of this approach is that you'll have to fetch the datafile on some interval on your own in order to get updates made to your feature flags.