a year ago
I have a next.js front end deployed as a railway project, when I set the $PORT variable to 3000, the service starts and works fine. If I remove the $PORT variable and just rely on the $PORT provided by railway, the project builds fine, but when I try to access the public url, I get a 502 Bad Gateway error.
Also, my front end connects to a backend service in the same project, if that backend also uses the provided $PORT from railway, can the frontend access it by setting its APIURL env var to "http://${{backend.RAILWAYPRIVATE_DOMAIN}}:${{backend.PORT}}"?
56 Replies
a year ago
please see our docs page -
I am not using target ports, but I must've missed the example for node/next. Do I need to set the address to listen on as "0.0.0.0" in next too?
a year ago
next by default should listen on the correct host, and how do you know you aren't using target ports?
as for crafting a API URL out of reference variables -
I just started the project with $ next start --port ${PORT-3000}, and I'm still getting the 502 bad gateway. I don't believe I'm using target ports since I'm not seeing that option in configuring the public network addresses
a year ago
show me a screenshot of your public domain please
a year ago
how do you know that is the start command that railway is using?
app:start: $ next start --port ${PORT-3000} app:start: ▲ Next.js 14.1.0 app:start: - Local: http://localhost:3000
it looks like it didn't use the $PORT injected by railway, and used port 3000 the fallback, but now the service is trying to connect to the $PORT and it's not working, but I'm just guessing
a year ago
I see localhost, not 0.0.0.0
that's the output from next start. Right, it's localhost, it's just the default I guess from next because I'm not setting the host anywhere in code
While that's going, I used the ${{backend.PORT}} var reference, but it doesn't show the autocomplete for it, so I wasn't sure if it's possible to do that, even though I read the docs
a year ago
have you set the PORT variable?
app:start: $ next start --hostname 0.0.0.0 --port ${PORT-3000} app:start: ▲ Next.js 14.1.0 app:start: - Local: http://localhost:3000 app:start: - Network: http://0.0.0.0:3000
a year ago
it's injected into the runtime, not your own service variables
a year ago
go ahead and set the port variable
ah ok, so if I want to reference ${{backend.PORT}} from frontend service, I have to set it on the backend service first, can't use the injected one
a year ago
right, you can't reference a variable that doesn't exist
a year ago
on this next service, set a PORT variable to 3000
a year ago
awesome
I was just trying to follow the docs and let the service use the injected $PORT 🙂
a year ago
I know, but something is missconfigured in your app and it's not listening on it, so this is easier
a year ago
feel free to cancel it
it rebuilt in 1 minute, deployed and back to working, having specified $PORT as 3000 in the env vars
a year ago
awsome
can I ask a question about redis storage or should I open up another question? I was just curious if that's also expandable to 10gb without adding a persistent volume?
a year ago
you need to use a volume with redis, what plan are you on
a year ago
then you can go up to 250GB
a year ago
(you dont pay for unused storage)
but I need to add a volume to the redis service? right now I don't have a volume backing it
a year ago
ah so you currently dont care if your redis data persists?
a year ago
okay because i was about to say you have a volume
so that's showing that the redis volume is using 1gb of storage, but the redis cache is pretty much empty
a year ago
yep so you will pay for 1GB of storage
I'm just wondering why it's using 1gb of storage since there's no data on it
a year ago
i honestly couldn't tell you, im not familiar with redis in depth
a year ago
no problem 🙂

