Error 503

Hi! I am trying to deploy and app created with React and Sequelize with PostgreSQL. I could connect the local front-end with the back-end in Railway, but when I try to connect fron-end in Railway with back-end in Railway, we receive and error. The message is: "Failed to load resource: the server responded with a status of 503 ()" I dont know why and how to fix it. I hope someone can help me. Thanks.
65 Replies
Percy
Percy17mo ago
Project ID: c28866fd-5fa3-41e6-8ebd-1ab29b18f9c9
Percy
Percy17mo ago
It appears that the issue was solved by removing the APP_PORT from the service variables and then using the const variable to listen on.
⚠️ experimental feature
Nicolás Bonder
Nicolás Bonder17mo ago
c28866fd-5fa3-41e6-8ebd-1ab29b18f9c9
Brody
Brody17mo ago
your app needs to listen on host 0.0.0.0 and environment variable PORT
Nicolás Bonder
Nicolás Bonder17mo ago
Sorry, it is the first time I do this deployment. Can you explain me a little more?
Nicolás Bonder
Nicolás Bonder17mo ago
So, in the front-end I should add a env variable? PORT = 0.0.0.0:$PORT ?
Brody
Brody17mo ago
if you are getting a 503 from the frontend domain then your frontend needs to listen on host 0.0.0.0 and environment variable PORT you do not need to set any PORT environment variables yourself
Nicolás Bonder
Nicolás Bonder17mo ago
I said add, because in the front-end I dont have a PORT variable
Brody
Brody17mo ago
you dont need to add one, railway generates and injects it, and your app should listen on it
Nicolás Bonder
Nicolás Bonder17mo ago
and if in the back-end, in the PORT variable, I use 0.0.0.0:$PORT, I get an error
Brody
Brody17mo ago
^
Nicolás Bonder
Nicolás Bonder17mo ago
Ok, now I understand that I dont have to add it. Now I need to know how can I do to my app listen that port? Should I change the port in my code? I guess is in the .env in the back-end
Brody
Brody17mo ago
no you shouldnt be using a .env file in railway wherever you start your app it needs to be setup to listen on environment variable PORT
Nicolás Bonder
Nicolás Bonder17mo ago
No, I dont use it in railway, I use it in my app,
Brody
Brody17mo ago
same thing
Nicolás Bonder
Nicolás Bonder17mo ago
Sorry man, I dont understand. That is what I did
Brody
Brody17mo ago
^
Nicolás Bonder
Nicolás Bonder17mo ago
ok, I will remote it
Brody
Brody17mo ago
^
Nicolás Bonder
Nicolás Bonder17mo ago
This is what I dont understand. I understand I should remote it from railway, but I dont understand what else I should do
Brody
Brody17mo ago
listen on the auto generated and injected PORT
Nicolás Bonder
Nicolás Bonder17mo ago
I am sorry, as I said, it is the first time I do it, and I am pretty new in all this. I have no idea how to listen that port. I removed the port I had, I tried to deploy again and I get this error: ERROR: executor failed running [/bin/bash -ol pipefail -c npm run build]: exit code: 1
Brody
Brody17mo ago
send your repo please
Nicolás Bonder
Nicolás Bonder17mo ago
Railway
Railway
Railway is an infrastructure platform where you can provision infrastructure, develop with that infrastructure locally, and then deploy to the cloud.
Brody
Brody17mo ago
that is not a github repository
Nicolás Bonder
Nicolás Bonder17mo ago
Hi, I had to leave yesterday. This is the back end repo: https://github.com/nicobonder/pg-henry-back and this is the front-end: https://github.com/nicobonder/PG-Henry
GitHub
GitHub - nicobonder/pg-henry-back: Proyecto grupal de Henry (back)
Proyecto grupal de Henry (back) . Contribute to nicobonder/pg-henry-back development by creating an account on GitHub.
GitHub
GitHub - nicobonder/PG-Henry: Proyecto Grupal para la finalización ...
Proyecto Grupal para la finalización del Bootcamp de Henry - GitHub - nicobonder/PG-Henry: Proyecto Grupal para la finalización del Bootcamp de Henry
Nicolás Bonder
Nicolás Bonder17mo ago
I saw you were helping someone else with the same issue and he solved using a PORT variable.
Ray
Ray17mo ago
In your backend, tweak your server.listen() calls to listen on 0.0.0.0 (https://stackoverflow.com/a/33957043). In your frontend, react-scripts will use HOST and PORT provided in environment, so all you need to do is add a HOST service variable in Railway and set it to 0.0.0.0.
Nicolás Bonder
Nicolás Bonder17mo ago
Hi rc, I tried what you said, but as soon as the deploy start, I get and error
Nicolás Bonder
Nicolás Bonder17mo ago
This is what I did in railway
Nicolás Bonder
Nicolás Bonder17mo ago
In my code, I have this: const PORT = process.env.PORT || 3000; if (process.env.NODE_ENV === 'production') { sequelize.sync({ force: true }).then(() => { setAllDb(); server.listen(PORT, () => { console.log(Server listening at port ${PORT}); }); }); } else { sequelize.sync({ force: true }).then(() => { setAllDb(); server.listen(PORT, () => { console.log(Server listening at port ${PORT}); }); }); }
Brody
Brody17mo ago
bruh 0.0.0.0 is not a port remove the PORT from your service variables all together
Nicolás Bonder
Nicolás Bonder17mo ago
Yes, you are right. I removed the PORT, but I keep seing: Failed to load resource: the server responded with a status of 503 ()
Brody
Brody17mo ago
show screenshot of deploy logs
Nicolás Bonder
Nicolás Bonder17mo ago
This is the back. I am starting again the front
Brody
Brody17mo ago
hey hey, one service at a time okay the backend says active, does it work?
Nicolás Bonder
Nicolás Bonder17mo ago
Yes...or at least I think it works.
Brody
Brody17mo ago
well check
Nicolás Bonder
Nicolás Bonder17mo ago
Brody
Brody17mo ago
test it
Nicolás Bonder
Nicolás Bonder17mo ago
How?
Brody
Brody17mo ago
call an endpoint in postman or the browser once you confirm the backend works, we can move on to getting the front-end running properly because even though it says active, it isn't running correctly
Nicolás Bonder
Nicolás Bonder17mo ago
Locally, I can see the app is working. Front and end are conecting
Brody
Brody17mo ago
okay so the backend on railway is working? yes or no
Nicolás Bonder
Nicolás Bonder17mo ago
bruh as I told you it is the first time I do everything, so I have no idea how to do this. I checked in me local app, and it is ok, in railway I see it says active and looks like it is working but I dont know how to be sure if it works or not. So if you can tell me how to check that, it would be great
Brody
Brody17mo ago
^
Nicolás Bonder
Nicolás Bonder17mo ago
I did that in the local app, and it works. I dont know how to do it to know if it works in Railway. If you try to open the railway app, it doesnt work. The link to the app is https://grooveticket.up.railway.app/
Brody
Brody17mo ago
is that the backend
Nicolás Bonder
Nicolás Bonder17mo ago
No, that is the front. The back end link is groove-back.up.railway.app
Brody
Brody17mo ago
does your backend have a path registered for the root?
Nicolás Bonder
Nicolás Bonder17mo ago
no
Brody
Brody17mo ago
whats a path i could hit that would tell me if its doing what it should
Nicolás Bonder
Nicolás Bonder17mo ago
In local enviroment, I use: http://localhost:3001/products and I see al the products
Brody
Brody17mo ago
okay so it works then
Brody
Brody17mo ago
Brody
Brody17mo ago
now onto frontend
Nicolás Bonder
Nicolás Bonder17mo ago
In the front is where I see the error: Failed to load resource: the server responded with a status of 503 ()
Nicolás Bonder
Nicolás Bonder17mo ago
Nicolás Bonder
Nicolás Bonder17mo ago
In build I see that
Brody
Brody17mo ago
yes, i know the problem change the start script to serve build -s -p $PORT and also do a npm i serve then commit the new changes
Nicolás Bonder
Nicolás Bonder17mo ago
Like this?
Brody
Brody17mo ago
so far so good, continue with the instructions
Nicolás Bonder
Nicolás Bonder17mo ago
YEAHHHHH!! It is working Thank you!!
Brody
Brody17mo ago
woohoo