How to resolve proxy issues with the JS SDK?

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.

Option 1: Set your proxy config via the proxy configuration option

The 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: '',
    port: 9000,
    auth: {
      username: 'mikeymike',
      password: 'rapunz3l'

Option 2: the 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.

Option 3: Environment variables on your machine might cause issues

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.

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,

1 Like