본문으로 건너뛰기
섹션
문서

Node.js 및 TypeScript

연결 풀을 활용하면서 undici, axios, 네이티브 fetch 또는 SOCKS5로 Node.js와 TypeScript 요청을 전용 고정 IPv4로 보내세요.

이 페이지의 목차8

적합한 클라이언트는 프록시 프로토콜과 Node.js 런타임 버전에 따라 달라지므로 스택에 맞는 패턴을 선택하세요.

클라이언트 프록시 스킴 적합한 용도
undici(ProxyAgent) https://, http:// fetch를 사용하는 Node 20+ 서버 및 서버리스 함수의 기본 권장
axios + https-proxy-agent https://, http:// 기존 axios 코드베이스
네이티브 fetch + NODE_USE_ENV_PROXY=1 https://, http:// Node 22.21+ 및 Node 24+에서 의존성 없이 사용
socks-proxy-agent socks5h:// SOCKS5가 필요한 node:https 또는 axios 클라이언트

1단계. 프록시 URL 가져오기

  1. Prontaro 대시보드(my.prontaro.com/ips)에서 IP 주소를 열고 전용 IPv4를 선택합니다.
  2. 프록시 인증 정보에서 HTTPS 프록시 URL(:443)을 복사합니다.
IP 주소프록시 자격 증명대시보드에서 열기

프록시 문자열을 PRONTARO_PROXY_URL로 내보냅니다.

bash
export PRONTARO_PROXY_URL="https://user:pass@<entry>.prontaro.io:443"

undici(ProxyAgent) — 권장

undici를 설치하고 요청들이 단일 TCP/TLS keep-alive 풀을 공유하도록 모듈 수준에 ProxyAgent를 하나만 생성하세요.

bash
npm install undici
ts
// egress-client.ts
import { fetch, ProxyAgent } from 'undici';

const proxyUrl = process.env.PRONTARO_PROXY_URL;
if (!proxyUrl) {
  throw new Error('PRONTARO_PROXY_URL is not set');
}

// One shared agent per process — do not close it after every request
export const proxyAgent = new ProxyAgent({
  uri: proxyUrl,
  connections: 10,
});

export async function checkOutboundIp(): Promise<string> {
  const res = await fetch('https://api.ipify.org', {
    dispatcher: proxyAgent,
    signal: AbortSignal.timeout(15_000),
  });

  if (!res.ok) {
    throw new Error(`HTTP ${res.status}: ${await res.text()}`);
  }
  return (await res.text()).trim();
}

// Close only during graceful process shutdown
process.once('SIGTERM', () => {
  void proxyAgent.close();
});

console.log(await checkOutboundIp());

발신 IP를 확인합니다.

npx tsx egress-client.ts
203.0.113.10

api.ipify.org가 전용 IPv4를 반환하는 것을 확인한 뒤 대시보드(IP 주소 → 프록시 인증 정보 → 접근)에서 목적지를 제한할 수 있습니다.

axios + https-proxy-agent

Axios의 내장 proxy 옵션은 https:// 프록시 호스트 처리에 문제가 있고 환경 변수와 충돌할 수 있습니다. HttpsProxyAgent를 httpsAgent로 전달하고 명시적으로 proxy: false를 설정하세요.

bash
npm install axios https-proxy-agent
ts
// axios-client.ts
import axios from 'axios';
import { HttpsProxyAgent } from 'https-proxy-agent';

const proxyUrl = process.env.PRONTARO_PROXY_URL;
if (!proxyUrl) {
  throw new Error('PRONTARO_PROXY_URL is not set');
}

const httpsAgent = new HttpsProxyAgent(proxyUrl);

export const partnerApi = axios.create({
  httpsAgent,
  proxy: false, // disable Axios's built-in HTTP_PROXY handling
  timeout: 15_000,
});

const { data } = await partnerApi.get<string>('https://api.ipify.org');
console.log(data.trim());

NODE_USE_ENV_PROXY=1과 네이티브 fetch(Node 22 / 24)

Node.js 24+ 및 Node.js 22.21+에서는 NODE_USE_ENV_PROXY=1(또는 --use-env-proxy)로 실행하면 내장 fetch()가 추가 의존성 없이 HTTPS_PROXY, HTTP_PROXY, NO_PROXY를 자동으로 따릅니다.

js
// check-env.mjs
const res = await fetch('https://api.ipify.org', {
  signal: AbortSignal.timeout(15_000),
});
if (!res.ok) {
  throw new Error(`HTTP ${res.status}`);
}
console.log((await res.text()).trim());
bash
HTTPS_PROXY="$PRONTARO_PROXY_URL" \
NO_PROXY="localhost,127.0.0.1,::1,169.254.169.254,.internal" \
NODE_USE_ENV_PROXY=1 \
node check-env.mjs

프로세스 내 모든 fetch() 호출에 적용되므로 내부 서비스와 텔레메트리가 Prontaro를 우회하도록 항상 NO_PROXY를 설정하세요.

socks-proxy-agent를 이용한 SOCKS5(socks5h://)

undici.ProxyAgent는 http://와 https://만 지원합니다. socks5h://(:1080)에는 SocksProxyAgent를 axios나 node:https와 함께 사용하세요.

bash
npm install axios socks-proxy-agent
ts
// socks-client.ts
import axios from 'axios';
import { SocksProxyAgent } from 'socks-proxy-agent';

// Use socks5h:// so DNS resolves on the Prontaro server
const socksUrl = process.env.PRONTARO_SOCKS_URL; // socks5h://user:pass@<entry>.prontaro.io:1080
if (!socksUrl) {
  throw new Error('PRONTARO_SOCKS_URL is not set');
}

const socksAgent = new SocksProxyAgent(socksUrl);

const { data } = await axios.get<string>('https://api.ipify.org', {
  httpAgent: socksAgent,
  httpsAgent: socksAgent,
  proxy: false,
  timeout: 15_000,
});
console.log(data.trim());

자주 발생하는 Node.js 실수

  • 전역 fetch와 npm undici 혼용: 내장 undici와의 버전 차이로 dispatcher가 깨지므로 fetch와 ProxyAgent 모두 'undici'에서 가져오세요.
  • axios에서 proxy: false 누락: httpsAgent와 함께 HTTPS_PROXY가 설정되어 있으면 Axios가 요청을 이중 프록시하려 시도합니다.
  • SocksProxyAgent를 fetch({ dispatcher })에 전달: SocksProxyAgent는 undici.Dispatcher가 아니라 Node의 http.Agent를 구현합니다.
  • 요청마다 에이전트 생성: 핸들러에서 new ProxyAgent(...)를 매번 만들면 TLS 핸드셰이크가 반복되어 IP당 동시 연결 한도에 도달할 수 있습니다.

Relay URL로 API 호출하기

프록시 에이전트를 설정할 수 없는 엣지 런타임이나 코드베이스에서는 대시보드(IP 주소)에서 Relay를 만들고 fetch로 직접 호출하세요.

ts
const res = await fetch(`${process.env.PRONTARO_RELAY_URL}/v1/status`, {
  headers: {
    Authorization: `Bearer ${process.env.PARTNER_API_TOKEN}`,
    // 비밀번호를 설정한 경우에만 포함(대시보드의 'IP 주소 → Relay 주소 → 접근'):
    'Prontaro-Relay-Auth': `${process.env.RELAY_LOGIN}:${process.env.RELAY_PASSWORD}`,
  },
  signal: AbortSignal.timeout(15_000),
});
if (!res.ok) {
  throw new Error(`HTTP ${res.status}: ${await res.text()}`);
}
console.log(await res.json());

TLS 종료 세부 사항과 한도는 Relay URL을 참고하세요.

다음 단계

이 페이지에 문제가 있나요? 문의하기

문의하기

답변받을 이메일 주소를 입력하세요.올바른 이메일 주소를 입력하세요. 예: name@company.example.
상황이나 필요한 내용을 입력하세요.최대 2,000자

전송했습니다. 입력하신 이메일()로 답변드리겠습니다.

또는 이메일로 support@prontaro.com