nextjs-request-url-proxy-redirect
Installation
SKILL.md
Next.js request.url Returns Internal Proxy URL on Containerized Platforms
Problem
When deploying Next.js to Railway, Vercel, or similar containerized platforms,
request.url in Edge runtime or API routes can return the internal proxy URL
(e.g., http://localhost:8080) instead of the public domain (e.g., https://example.com).
This causes NextResponse.redirect(new URL(path, request.url)) to redirect users
to the internal URL, which fails with ERR_CONNECTION_REFUSED.
Context / Trigger Conditions
- Symptom: Browser shows
ERR_CONNECTION_REFUSEDtolocalhost:8080or similar - Console errors:
Failed to fetch RSC payloadfollowed by connection refused - Network tab: Shows 307 redirect to
https://localhost:8080/... - Environment: Next.js deployed to Railway, Vercel, Docker, or any reverse proxy setup
- Code pattern: Using
new URL('/path', request.url)for redirects