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

2 messages · Page 1 of 1 (latest)

languid steeple
#

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?

novel rockBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)