502 on app with correct HOST and PORT
Hi, friends! I'm deploying a new app on railway, I've followed the guides without problem.
The build was successful, the application is running, but I can't access this, because I'm getting a 502 status code.
https://docs.railway.app/guides/fixing-common-errors
I've followed this guide but didn't solved my problem.
I'm already using the PORT that railway provides and the host is set to 0.0.0.0
Am I missing something?
59 Replies
Project ID:
75f448f4-88c9-4d82-b428-61740d90e40c
75f448f4-88c9-4d82-b428-61740d90e40c
My public route is this:
niki-backend-homolog.up.railway.app
It just works if I specify the app port to 3000 on railway env :/
hey, send your
app.listen
.
I also use nest and have no problems, pretty weird.I don't even need the 0.0.0.0, maybe you could give it a try?
but anyway, the port env would work without any problems.
k, imma try removing the 0.0.0.0
but it was not working also
still not working
when i removed the 0.0.0.0 and port
just works when i specify the port :/
weird, are u using fastify or express?
fastify
hmmm im using express so it might have a difference
hmm maybe
I guess I've an application where I used fastify but anyway the port env should be working alright so I guess there's no need to do something about it
i see a question here with the same problem, probably?
https://help.railway.app/questions/my-backend-is-launched-without-probleme-9970071f
without solution
(when I specify the port it works)
should I specify this and just move forward?
should I have any problem by doing this?
couldnt find any other issue related to fastify and 502
yep its alright
oh, i have another problem
the database cannot connect to run migrations without the public url
my build command runs the migrations before the build
to keep the db up-to-date
but it just works when I add an env variable with the public database url
the private networking isn't available at build unfortunately.
in my case I do the migration on the start script
hmm
is there any problem to use the public url?
(just for migrations)
by using public url you'll be charged more by bandwidth.
I don't know how much you would but I'm pretty sure it would be cheap
hmm, it is used only at migrations, so I guess there is no problem
If you're sure of that then ok
but tbh I would just move the migration script to the start command
you put migrations before start, right?
with && operator
yep, are u using prisma?
if migrations fail, you dont start?
typeorm
ah typeorm
okay, imma try this approach
put it on start script
yep but my backend contains a healthcheck
if yours dont then it would just fail
but its pretty simple to setup one
https://docs.nestjs.com/recipes/terminus#setting-up-a-healthcheck
Documentation | NestJS - A progressive Node.js framework
Documentation | NestJS - A progressive Node.js framework
Nest is a framework for building efficient, scalable Node.js server-side applications. It uses progressive JavaScript, is built with TypeScript and combines elements of OOP (Object Oriented Programming), FP (Functional Programming), and FRP (Functional Reactive Programming).
lemme understand
in this case, what does the healthcheck change?
this is my script with prisma:
i didnt set a healthcheck yet
Railway will hold the deployment of your application until its actually reachable by doing an HTTP ping to a
/health
endpoint
you've to configure it in the service settingsoh, so it will not stop trying to restart until the app is up?
trying to restart? you mean an infinite loop of fail restart?
yup
nope, thats another setting
where should I configure health route?
go to your service settings and scroll down until you see that
oh good
will this be enough?
yep it should be alright
nestjs also offers the option to check your database and other external services but thats optional, that health controller will work
https://docs.nestjs.com/recipes/terminus#setting-up-a-healthcheck
imma see them later, if my db is down, the routes will be the smaller problem lmao
makes sense :kekw:
ive added the route, but its not working, probably because previous deploy was not with port
wdym by not working? 502 or build not going through?
502
the deploy with the port is not working
because the previous one was the health one
and the status is 502, because there is no port yet
š¤£
removed healthcheck for a while
no port yet? Railway should just do a load balance so both of the deploys will contain the port
the problem was the 0.0.0.0 probably
it appears to be needed on fastify apps
yep, i'll see if I can get my fastify app to see what I did but it just worked š
gods with u
yep it just works š
not using process to env? š
interesting
u use redis in any of your nest apps?
deployed on railway
yes
does it worth it?
you mean in terms of pricing?
yes
instead of using the instance memory itself
well Railway's memory pricing is not that cheap but if your just using for cache it should be alright
well, health check is now working
obrigado amigo
late night, imma sleep
I used to host a bullmq queue with at least 16k per minute inserts and it was pretty cheap IMO
great!
boa noite!