8 months ago
We are in the process of migrating our Next.js app from Vercel to Railway in a Medusa.js e-commerce setup. During testing, we encountered an issue where all server requests are still being routed to localhost:8080 instead of the Railway app URL. As we are relatively new to Railway and not fully acquainted with its settings compared to Vercel, we are seeking assistance from the Railway team.
We would greatly appreciate it if someone could review our deployment setup and guide us on whether everything is configured correctly. Additionally, if possible, we would be grateful for a step-by-step guide for deploying a Next.js app on Railway.
Please let us know your availability for a meeting or if you can share detailed instructions for the deployment process.
6 Replies
8 months ago
Hey there! We've found the following might help you get unblocked faster:
🧵 Railway Support Request - Internal Database Connection Failure
🧵 Service fails with 502 error on specific path /plan/ - Request not reaching application
If you find the answer from one of these, please let us know by solving the thread!
8 months ago
Hi, the issue is still not resolved. We're still seeing requests routed to localhost:8080. Could you please provide direct guidance or a support contact to help us properly set up this project on Railway?
8 months ago
This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.
Status changed to Open itsrems • 8 months ago
piacademy
Hi, the issue is still not resolved. We're still seeing requests routed to localhost:8080. Could you please provide direct guidance or a support contact to help us properly set up this project on Railway?
8 months ago
Hi piacademy, I would be happy to assist you in this, would it be possible to share your github repo or add me if it's private ?
8 months ago
Thank you for your response. Unfortunately, I can't share the repository due to privacy concerns. However, the issue we're facing is that, despite configuring the port to 8080, our app continues to deploy to localhost:8080 instead of the Railway app URL. We're unsure if this behavior is specific to Railway or if there's something we're missing in the configuration. Any guidance you can provide would be greatly appreciated!
middleware.ts :
const handler = clerkMiddleware(async (auth, request) => {
const { userId } = await auth()
const pathname = request.nextUrl.pathname.split('%2F').join('/')
console.log('[MIDDLEWARE] Request:', {
userId,
pathname,
url: request.url,
})
Due to this issue with the deployment on localhost, the NextRequest.url is resolving to localhost:8080 (as shown in the screenshot), which is causing the misrouting of server requests.
Attachments
piacademy
Thank you for your response. Unfortunately, I can't share the repository due to privacy concerns. However, the issue we're facing is that, despite configuring the port to 8080, our app continues to deploy to localhost:8080 instead of the Railway app URL. We're unsure if this behavior is specific to Railway or if there's something we're missing in the configuration. Any guidance you can provide would be greatly appreciated!middleware.ts :const handler = clerkMiddleware(async (auth, request) => { const { userId } = await auth() const pathname = request.nextUrl.pathname.split('%2F').join('/') console.log('[MIDDLEWARE] Request:', { userId, pathname, url: request.url, })Due to this issue with the deployment on localhost, the NextRequest.url is resolving to localhost:8080 (as shown in the screenshot), which is causing the misrouting of server requests.
8 months ago
You need to instead be looking for X-Forwarded-Host header. It will have the correct railway public domain that was used to visit, be it railway assigned domain or a custom domain.
const handler = clerkMiddleware(async (auth, request) => {
const { userId } = await auth()
const pathname = request.nextUrl.pathname.split('%2F').join('/')
// Get the actual external URL from headers
const host = request.headers.get('x-forwarded-host')
const protocol = request.headers.get('x-forwarded-proto') || 'https'
console.log('[MIDDLEWARE] Request:', {
userId,
pathname,
url: `${protocol}://${host}${pathname}`
})
})7 months ago
Hey piacademy, Did that solve the problem you were facing ?