Nextjs redirect to localhost instead of domain
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-5Railway Help Station
Next.js route handler is returning localhost when deployed on Railway.
Hi team,I have been deploying several Next.js apps on Railway, and so far it works fine. However, I have encountered an unusual error in this particular project. In the route handler, the URL from the request object returns "localhost" instead of the configured domain.Here's how I tested:route.ts```export const dynamic = 'force-dynamic'export as...
Solution:Jump to solution
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....
3 Replies
Project ID:
bf45f30b-226a-48ed-b949-ff535767440c
bf45f30b-226a-48ed-b949-ff535767440c
Reproduction project: dc49af26-8011-4680-a83d-219a87075e8b
Solution
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.