request.url is wrongly returning localhost:3000 for non-Vercel plattforms
Unanswered
Belgian Hare posted this in #help-forum
Belgian HareOP
The following snippet:
redirects to
But on other plattforms such as fly.io redirects to
What am I missing? Is there a missing config or env var that vercel is injecting by default with the domain value?
Is this documented somewhere?
export async function POST(request: NextRequest) {
const requestUrl = new URL(request.url);
return NextResponse.redirect(
`${requestUrl.origin}/something`,
{
status: 301,
},
);redirects to
mydomain.com/something on vercel (which is the expected outcome). But on other plattforms such as fly.io redirects to
localhost:3000/somethingWhat am I missing? Is there a missing config or env var that vercel is injecting by default with the domain value?
Is this documented somewhere?
1 Reply
@Belgian Hare The following snippet:
export async function POST(request: NextRequest) {
const requestUrl = new URL(request.url);
return NextResponse.redirect(
`${requestUrl.origin}/something`,
{
status: 301,
},
);
redirects to `mydomain.com/something` on vercel (which is the expected outcome).
But on other plattforms such as fly.io redirects to `localhost:3000/something`
What am I missing? Is there a missing config or env var that vercel is injecting by default with the domain value?
Is this documented somewhere?
I think its better to redirect like this
return NextResponse.redirect(new URL("/something", request.url))