Next.js Discord

Discord Forum

request.url is wrongly returning localhost:3000 for non-Vercel plattforms

Unanswered
Belgian Hare posted this in #help-forum
Open in Discord
Belgian HareOP
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?

1 Reply