8 months ago
I am trying to get my NextJS application (on Railway) to access my NestJS application (on Railway).
I am trying to use the internal hostname and using the reference variable syntax. It is not working. See log image.
If I use the public domain, it works. But I do not want deal with egress fees. I need the internal domain to work.
I followed the docs at https://docs.railway.com/guides/private-networking
and used the BACKEND_URL=http://${{api.RAILWAY_PRIVATE_DOMAIN}}:${{api.PORT}} syntax
4 Replies
8 months ago
Hey there, happy to provide assistance :)
It seems like you're trying to connect your NextJS application to your NestJS application using the Railway internal URL but running into issues. The key to making internal connections work is ensuring both your services are properly configured to use Railway's private networking.
Here are a few points to check:
Ensure IPv6 Binding: Since Railway's private network is IPv6 only, make sure both your NextJS and NestJS applications are configured to listen on IPv6. For NextJS, update your start command to bind to both IPv4 and IPv6 using:
next start --hostname :: --port ${PORT-3000}For NestJS, ensure your application is set to listen on :::
async function bootstrap() {
await app.listen(process.env.PORT || 3000, '::');
}Reference Variable Setup: Verify that the
RAILWAY_PRIVATE_DOMAINandPORTare correctly referenced in your environment variables. It’s crucial thatapi.PORTis set manually in your environment variables, as it doesn't automatically resolve to the service's listening port.Use Internal DNS: Make sure your service names are correctly set in the Railway project, like
api.railway.internal. Ensure there are no typos, and the service name matches exactly.
If these adjustments don't resolve the issue, you can refer to the Private Networking Guide for more detailed configuration steps. This should help you avoid egress fees and optimize the internal communication between your services. Let me know if you need more help!
Status changed to Awaiting User Response Railway • 8 months ago
8 months ago
It is still not clear to me how to use the internal name. I tried using the below but did not work.
Ive tried setting my env variable to:
- gridlq
- http://gridlq
- http://gridlq.railway.internal
Status changed to Awaiting Railway Response Railway • 8 months ago
8 months ago
It has to be something with the internal url I am using but I don't know what it should be.
Attachments
8 months ago
Closing in favor of your newer thread.
https://station.railway.com/questions/next-js-error-application-error-a-serve-a340db80
Status changed to Awaiting User Response Railway • 8 months ago
Status changed to Closed brody • 8 months ago
