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,
});

Delivery API 작업에는 기존 spaceId/accessToken와 이 클라이언트를 사용합니다. 의존성은 이미 갖춰진 것으로 봅니다. 공개 중개자를 통한 허용된 공개 Delivery API 요청에는 HTTP 프록시 목록이 에이전트의 HTTP 프록시 URL 후보를 제공합니다.

기본 API는 HTTPS를 쓰므로 httpsAgent가 선택됩니다. 그 에이전트는 HTTP 프록시 리스너에 닿아 CONNECT를 맺을 수 있습니다. proxy:false는 Axios가 다른 프록시 선택을 덧붙이지 못하게 합니다.

명시적인 Node http 어댑터가 중요합니다. 브라우저 네트워킹과 다른 어댑터는 이 필드로 Node 소켓 경로를 얻지 못합니다. 클라이언트 작업 동안 에이전트를 유지하고 종료 시 요청이 끝난 뒤 해제하세요.

관련 글