When your frontend dev server proxies API requests to another portless app, you need to configure the proxy to rewrite theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/vercel-labs/portless/llms.txt
Use this file to discover all available pages before exploring further.
Host header. Without this, portless will detect a routing loop and respond with a 508 Loop Detected error.
The Problem
When a frontend dev server (like Vite or webpack) proxies a request without rewriting headers, it forwards the originalHost header from the browser. For example:
- Browser sends request to
http://frontend.localhost:1355/api/users - Frontend dev server proxies to
http://api.localhost:1355/api/users - Without
changeOrigin: TheHostheader remainsfrontend.localhost - Portless routes the request back to the frontend based on the
Hostheader - The frontend proxies it again, creating an infinite loop
X-Portless-Hops header. After 5 hops, it rejects the request with a 508 Loop Detected error.
The Solution: changeOrigin
Set changeOrigin: true in your proxy configuration to rewrite the Host header to match the target:
Vite
Invite.config.ts or vite.config.js:
webpack-dev-server
Inwebpack.config.js:
Next.js
Innext.config.js:
Host header correctly by default.
What changeOrigin Does
When changeOrigin: true is set:
- Browser sends request with
Host: frontend.localhost - Frontend dev server changes the
Hostheader toapi.localhost(matching the target) - Portless receives the request with
Host: api.localhost - Portless correctly routes to the API backend
- No loop occurs
X-Forwarded-Host to preserve the original host for debugging.
Loop Detection Details
Portless uses theX-Portless-Hops header to count how many times a request has passed through the proxy:
- Maximum hops: 5 (allows multi-tier setups while catching loops quickly)
- Normal usage: 1-2 hops (browser → proxy → app, or frontend → proxy → API → proxy → backend)
- Error response:
508 Loop Detectedwith an HTML page explaining the fix
Wildcard Subdomains and Proxying
When using wildcard subdomains (e.g.,tenant1.myapp.localhost, tenant2.myapp.localhost), the same changeOrigin requirement applies. The proxy must rewrite the Host header to match the registered route:
Debugging Proxy Issues
If you’re experiencing routing problems:- Check the error page: Portless shows a detailed
508error with the exact configuration needed - Inspect headers: Use browser DevTools to verify the
Hostheader in proxied requests - Check registered routes: Run
portless listto see which apps are registered - Test direct access: Visit the backend URL directly to verify it’s running
WebSocket Proxying
WebSocket upgrades also requirechangeOrigin to avoid loop detection:
508 Loop Detected message if the limit is exceeded.