Overview
ofetch supports proxy configuration across different JavaScript runtimes, with each runtime having its own approach to proxy handling.Environment Variables
All runtimes support standard proxy environment variables:- Node.js
- Bun
- Deno
Node.js requires an additional environment variable:
Node.js Proxy Configuration
Node.js (>= 18) uses undici’sProxyAgent for proxy support.
Basic Usage
Global Proxy
Set a proxy for all requests:Per-Instance Proxy
Create a fetch instance with a proxy:Authenticated Proxy
Proxy from Environment
Bun Proxy Configuration
Bun has native proxy support through theproxy option.
Basic Usage
With Authentication
Per-Instance Proxy
Deno Proxy Configuration
Deno can use environment variables or undici with npm specifiers.Using Environment Variables
Using Undici (Programmatic)
Complete Example from Source
Fromexamples/proxy.mjs:
Self-Signed Certificates
Node.js (undici Agent)
Combined Proxy + Self-Signed Cert
Dispatcher Type Definition
Fromsrc/types.ts:50-54:
dispatcher option:
- Only available in Node.js >= 18
- Uses undici’s Dispatcher interface
- Supports
ProxyAgent,Agent, and other dispatcher types