Problem
We have a Next.js app deployed on Vercel, but it’s reached via an external edge/proxy layer that routes requests from a public domain (e.g., myapp.com) to a Vercel origin host (e.g., myapp.vercel.com). After upgrading to Next.js and moving our logic into proxy.ts, we hit two issues:
Current Behavior
- In
proxy.ts,NextResponse.redirect()requires absolute URLs.
Error: URL is malformed … use only absolute URLs
- In production,
request.urlandrequest.nextUrlappear to be anchored to the origin host (myapp.vercel.com), not the public host. So any redirects end up inmyapp.vercel.cominstead ofmyapp.com.
We tried relying on X-Forwarded-Host as the public host signal, but in our setup it appears to be overwritten/normalized before it reaches the Vercel runtime (we see it equal to the origin host).
Question
What’s the recommended Vercel approach to preserve the end-user host for redirects in this architecture?
- Is there a specific header we should inject at the proxy layer that
Vercelwill preserve reliably (e.g., a customX-Public-Host), or a documented way to ensureX-Forwarded-Hostarrives unchanged? - Is there a standard
Vercelconfig / header behavior we should enable for reverse-proxy scenarios soNext.jssees the public host? - Any best-practice pattern for
Next.jsProxy redirects behind a separate CDN/edge proxy?