shlogg · Early preview
Adam @urbanisierung

Configuring Proxies With NodeJS And Undici

NodeJS fetch client doesn't support proxies out-of-the-box but you can use `EnvHttpProxyAgent` from `undici` to handle env vars like `https_proxy`, `http_proxy` and `no_proxy`.

There is an established standard by which proxies are configured. It runs via the following environment variables:

https_proxy: Proxy for https traffic
http_proxy: Proxy for http traffic
no_proxy: URLs that should not run via a proxy.

The native fetch client of NodeJS does not offer any functionality for this out-of-the-box, but there is an agent from the undici http client that you can use:

import { EnvHttpProxyAgent } from "undici";
const ENV_HTTP_PROXY_AGENT = new EnvHttpProxyAgent();
const proxyAgent = { dispatcher: ENV_HTTP_PROXY_AGENT } as any;
await fetch("https://...", {
  ...proxyA...