502 on app with correct HOST and PORT
theo-nejm
HOBBYOP

2 years ago

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?

95 Replies

theo-nejm
HOBBYOP

2 years ago

75f448f4-88c9-4d82-b428-61740d90e40c


theo-nejm
HOBBYOP

2 years ago

My public route is this:
niki-backend-homolog.up.railway.app


theo-nejm
HOBBYOP

2 years ago

It just works if I specify the app port to 3000 on railway env :/


2 years ago

hey, send your app.listen.
I also use nest and have no problems, pretty weird.


theo-nejm
HOBBYOP

2 years ago

await app.listen(process.env.PORT || 3000, '0.0.0.0');


2 years ago

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.

1278189202911137800


theo-nejm
HOBBYOP

2 years ago

k, imma try removing the 0.0.0.0


theo-nejm
HOBBYOP

2 years ago

but it was not working also


theo-nejm
HOBBYOP

2 years ago

still not working


theo-nejm
HOBBYOP

2 years ago

when i removed the 0.0.0.0 and port


theo-nejm
HOBBYOP

2 years ago

just works when i specify the port :/


2 years ago

weird, are u using fastify or express?


theo-nejm
HOBBYOP

2 years ago

fastify


2 years ago

hmmm im using express so it might have a difference


theo-nejm
HOBBYOP

2 years ago

hmm maybe


2 years ago

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


theo-nejm
HOBBYOP

2 years ago


theo-nejm
HOBBYOP

2 years ago

without solution


theo-nejm
HOBBYOP

2 years ago

(when I specify the port it works)


theo-nejm
HOBBYOP

2 years ago

should I specify this and just move forward?


theo-nejm
HOBBYOP

2 years ago

should I have any problem by doing this?


2 years ago

couldnt find any other issue related to fastify and 502


2 years ago

yep its alright


theo-nejm
HOBBYOP

2 years ago

oh, i have another problem


theo-nejm
HOBBYOP

2 years ago

the database cannot connect to run migrations without the public url


theo-nejm
HOBBYOP

2 years ago

my build command runs the migrations before the build


theo-nejm
HOBBYOP

2 years ago

to keep the db up-to-date


theo-nejm
HOBBYOP

2 years ago

but it just works when I add an env variable with the public database url


2 years ago

the private networking isn't available at build unfortunately.
in my case I do the migration on the start script


theo-nejm
HOBBYOP

2 years ago

hmm


theo-nejm
HOBBYOP

2 years ago

is there any problem to use the public url?


theo-nejm
HOBBYOP

2 years ago

(just for migrations)


2 years ago

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


theo-nejm
HOBBYOP

2 years ago

hmm, it is used only at migrations, so I guess there is no problem


2 years ago

If you're sure of that then ok


2 years ago

but tbh I would just move the migration script to the start command


theo-nejm
HOBBYOP

2 years ago

you put migrations before start, right?


theo-nejm
HOBBYOP

2 years ago

with && operator


2 years ago

yep, are u using prisma?


theo-nejm
HOBBYOP

2 years ago

if migrations fail, you dont start?


theo-nejm
HOBBYOP

2 years ago

typeorm


2 years ago

ah typeorm


theo-nejm
HOBBYOP

2 years ago

okay, imma try this approach


theo-nejm
HOBBYOP

2 years ago

put it on start script


2 years ago

yep but my backend contains a healthcheck
if yours dont then it would just fail



theo-nejm
HOBBYOP

2 years ago

lemme understand
in this case, what does the healthcheck change?


2 years ago

this is my script with prisma:

"start": "prisma generate --no-hints && prisma migrate deploy && node dist/src/main",

theo-nejm
HOBBYOP

2 years ago

i didnt set a healthcheck yet


2 years ago

Railway will hold the deployment of your application until its actually reachable by doing an HTTP ping to a /health endpoint


2 years ago

you've to configure it in the service settings


theo-nejm
HOBBYOP

2 years ago

oh, so it will not stop trying to restart until the app is up?


2 years ago

trying to restart? you mean an infinite loop of fail restart?


theo-nejm
HOBBYOP

2 years ago

yup


2 years ago

nope, thats another setting

1278193155992195000


theo-nejm
HOBBYOP

2 years ago

where should I configure health route?


2 years ago

1278193469931917300


2 years ago

go to your service settings and scroll down until you see that


theo-nejm
HOBBYOP

2 years ago

oh good


theo-nejm
HOBBYOP

2 years ago

will this be enough?

@Controller('health')
export class HealthController {
  @Get()
  healthCheck() {
    return { ok: true };
  }
}

2 years ago

yep it should be alright


2 years ago

nestjs also offers the option to check your database and other external services but thats optional, that health controller will work


theo-nejm
HOBBYOP

2 years ago

imma see them later, if my db is down, the routes will be the smaller problem lmao


2 years ago

makes sense <:kekw:788259314607325204>


theo-nejm
HOBBYOP

2 years ago

ive added the route, but its not working, probably because previous deploy was not with port


2 years ago

wdym by not working? 502 or build not going through?


theo-nejm
HOBBYOP

2 years ago

502


theo-nejm
HOBBYOP

2 years ago

the deploy with the port is not working


theo-nejm
HOBBYOP

2 years ago

because the previous one was the health one


theo-nejm
HOBBYOP

2 years ago

and the status is 502, because there is no port yet


theo-nejm
HOBBYOP

2 years ago

🤣


theo-nejm
HOBBYOP

2 years ago

removed healthcheck for a while


2 years ago

no port yet? Railway should just do a load balance so both of the deploys will contain the port


theo-nejm
HOBBYOP

2 years ago

the problem was the 0.0.0.0 probably


theo-nejm
HOBBYOP

2 years ago

it appears to be needed on fastify apps


2 years ago

yep, i'll see if I can get my fastify app to see what I did but it just worked 💀


theo-nejm
HOBBYOP

2 years ago

gods with u


2 years ago

yep it just works 💀

1278197666362294300


theo-nejm
HOBBYOP

2 years ago

not using process to env? 😕


2 years ago

I use to validate my env variables and then import it elsewhere


theo-nejm
HOBBYOP

2 years ago

interesting


theo-nejm
HOBBYOP

2 years ago

u use redis in any of your nest apps?


theo-nejm
HOBBYOP

2 years ago

deployed on railway


2 years ago

yes


theo-nejm
HOBBYOP

2 years ago

does it worth it?


2 years ago

you mean in terms of pricing?


theo-nejm
HOBBYOP

2 years ago

yes


theo-nejm
HOBBYOP

2 years ago

instead of using the instance memory itself


2 years ago

well Railway's memory pricing is not that cheap but if your just using for cache it should be alright


theo-nejm
HOBBYOP

2 years ago

well, health check is now working


theo-nejm
HOBBYOP

2 years ago

obrigado amigo


theo-nejm
HOBBYOP

2 years ago

late night, imma sleep


2 years ago

I used to host a bullmq queue with at least 16k per minute inserts and it was pretty cheap IMO


2 years ago

great!


2 years ago

boa noite!


Loading...