import { createClient } from 'contentful';
import { HttpsProxyAgent } from 'https-proxy-agent';

const agent = new HttpsProxyAgent('http://proxy.example:8080');
const client = createClient({
  space: spaceId,
  accessToken,
  adapter: 'http',
  httpsAgent: agent,
  proxy: false,
});

Use existing spaceId/accessToken and this client for Delivery API operations. The dependencies are assumed already available. For permitted public Delivery API requests through a public intermediary, the HTTP proxy list supplies candidates for the agent’s HTTP proxy URL.

The default API uses HTTPS, selecting httpsAgent. That agent can reach an HTTP proxy listener and establish CONNECT. proxy:false prevents Axios from adding another proxy selection.

The explicit Node http adapter matters: browser networking and other adapters do not acquire a Node socket route from these fields. Keep the agent through the client workload and release it after requests finish at shutdown.

Ũhoro ũhĩtĩte