Nextjs redirect to localhost instead of domain

farreldarianPRO

7 months ago

I've deployed several Next.js applications on Railway, but I recently encountered this odd behavior with Response.redirect. Strangely, it redirects to localhost instead of the configured domain. I'm wondering if this issue is related to the latest Next.js update or perhaps with the Railway Edge Proxy.

I created a clean new Next.js app for testing, and the problem persists. However, when I deployed it to other platform like Vercel, the issue disappeared.

Link to original issue with reproduction:
https://help.railway.app/questions/next-js-route-handler-is-returning-local-683ba64f#p-5

0 Replies

farreldarianPRO

7 months ago

bf45f30b-226a-48ed-b949-ff535767440c


farreldarianPRO

7 months ago

Reproduction project: dc49af26-8011-4680-a83d-219a87075e8b


7 months ago

Vercel will strip localhost or replace it with your app's public domain.

Railway will not monkey patch your app, Railway will only ever run it as-is.

You will need to tell your code to either use the public domain or strip localhost yourself.

This would not have anything to do with the Railway platform.


Nextjs redirect to localhost instead of domain - Railway Help Station