fetch-proxy to create fetch handlers that forward requests to target servers while optionally rewriting headers and cookies.
Features
- Web Standards - Built on the standard JavaScript Fetch API
- Cookie Rewriting - Supports rewriting
Set-Cookieheaders received from target server - Forwarding Headers - Supports
X-Forwarded-ProtoandX-Forwarded-Hostheaders - Custom Fetch - Supports custom fetch implementations
Installation
API Reference
createFetchProxy
Create a fetch proxy handler that forwards requests to a target server.The base URL of the target server to proxy requests to
Configuration options for the proxy
FetchProxyOptions
Custom fetch implementation to use for making requests. Defaults to global
fetch.Whether to rewrite
Set-Cookie headers. If true, rewrites cookies to remove Domain and Secure attributes. If a function, allows custom cookie rewriting.Whether to add
X-Forwarded-Proto and X-Forwarded-Host headers. Defaults to true.Returns
A fetch handler that proxies requests to the target server
Usage Examples
Basic Proxy
Create a simple proxy that forwards all requests:Cookie Rewriting
Rewrite cookies from the target server:Custom Fetch Implementation
Use a custom fetch implementation with additional headers or authentication:Disable Forwarded Headers
DisableX-Forwarded-* headers if not needed:
Use Cases
- API Gateway - Route requests to multiple backend services
- Development Proxy - Proxy API requests during local development
- CORS Workaround - Proxy requests to avoid CORS restrictions
- Request Transformation - Modify requests/responses between client and server
- Load Balancing - Distribute requests across multiple backend servers
Related Documentation
Fetch Router
Build routers with fetch handlers
Headers
Work with HTTP headers