I have trouble connecting with the JavaScript SDK via my proxy to Contentful.
Which options do I have to fix this issue?
I have trouble connecting with the JavaScript SDK via my proxy to Contentful.
Which options do I have to fix this issue?
Hey there,
using proxies with our JS SDK can be a little bit tricky. The main reason is our dependency Axios which automatically tries to use the correct proxy settings. This turns out to be problematic for some users.
proxy
configuration optionThe proxy config is just passed to Axios, that’s why you can use the same format as in the Axios documentation:
const client = ContentfulManagement.createClient({
accessToken: <YOUR_ACCESS_TOKEN>,
proxy: {
host: '127.0.0.1',
port: 9000,
auth: {
username: 'mikeymike',
password: 'rapunz3l'
}
}
})
httpAgent
option got split up into httpAgent
and httpsAgent
Our dependency axios “quietly” split up their httpAgent
into one for every protocol (http & https).
We catched this too late, this is why the change went into the SDK as minor/feature release instead as a major/breaking release. Sorry for this, usually we try to avoid breaking changes within major releases.
Axios automatically picks up environment variables and uses these as proxy configuration. It can help to remove these from node’s process.env
object before you run the SDK.
delete process.env['http_proxy']
delete process.env['HTTP_PROXY']
delete process.env['https_proxy']
delete process.env['HTTPS_PROXY']
There is a pull request open in the Axios repository adding a possibility to disable this behavior. https://github.com/mzabriskie/axios/pull/691
On mid/long-term we try to eliminate the axios dependency completely, automatically resolving especially the last workaround.
Good luck, since proxies can be difficult to set up,
Benedikt