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
Percy2y ago
Project ID: c28866fd-5fa3-41e6-8ebd-1ab29b18f9c9
Percy
Percy2y 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 BonderOP2y ago
c28866fd-5fa3-41e6-8ebd-1ab29b18f9c9
Brody
Brody2y ago
your app needs to listen on host 0.0.0.0 and environment variable PORT
Nicolás Bonder
Nicolás BonderOP2y ago
Sorry, it is the first time I do this deployment. Can you explain me a little more?
Nicolás Bonder
Nicolás BonderOP2y ago
So, in the front-end I should add a env variable? PORT = 0.0.0.0:$PORT ?
Brody
Brody2y 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 BonderOP2y ago
I said add, because in the front-end I dont have a PORT variable
Brody
Brody2y ago
you dont need to add one, railway generates and injects it, and your app should listen on it
Nicolás Bonder
Nicolás BonderOP2y ago
and if in the back-end, in the PORT variable, I use 0.0.0.0:$PORT, I get an error
Brody
Brody2y ago
^
Nicolás Bonder
Nicolás BonderOP2y 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
Brody2y 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 BonderOP2y ago
No, I dont use it in railway, I use it in my app,
Brody
Brody2y ago
same thing
Nicolás Bonder
Nicolás BonderOP2y ago
Sorry man, I dont understand. That is what I did
Brody
Brody2y ago
^
Nicolás Bonder
Nicolás BonderOP2y ago
ok, I will remote it
Brody
Brody2y ago
^
Nicolás Bonder
Nicolás BonderOP2y 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
Brody2y ago
listen on the auto generated and injected PORT
Nicolás Bonder
Nicolás BonderOP2y 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
Brody2y ago
send your repo please
Nicolás Bonder
Nicolás BonderOP2y 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
Brody2y ago
that is not a github repository
Nicolás Bonder
Nicolás BonderOP2y 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 BonderOP2y ago
I saw you were helping someone else with the same issue and he solved using a PORT variable.
Ray
Ray2y 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 BonderOP2y ago
Hi rc, I tried what you said, but as soon as the deploy start, I get and error
Nicolás Bonder
Nicolás BonderOP2y ago
This is what I did in railway
Nicolás Bonder
Nicolás BonderOP2y 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
Brody2y ago
bruh 0.0.0.0 is not a port remove the PORT from your service variables all together
Nicolás Bonder
Nicolás BonderOP2y 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
Brody2y ago
show screenshot of deploy logs
Nicolás Bonder
Nicolás BonderOP2y ago
This is the back. I am starting again the front
Brody
Brody2y ago
hey hey, one service at a time okay the backend says active, does it work?
Nicolás Bonder
Nicolás BonderOP2y ago
Yes...or at least I think it works.
Brody
Brody2y ago
well check
Nicolás Bonder
Nicolás BonderOP2y ago
Brody
Brody2y ago
test it
Nicolás Bonder
Nicolás BonderOP2y ago
How?
Brody
Brody2y 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 BonderOP2y ago
Locally, I can see the app is working. Front and end are conecting
Brody
Brody2y ago
okay so the backend on railway is working? yes or no
Nicolás Bonder
Nicolás BonderOP2y 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
Brody2y ago
^
Nicolás Bonder
Nicolás BonderOP2y 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
Brody2y ago
is that the backend
Nicolás Bonder
Nicolás BonderOP2y ago
No, that is the front. The back end link is groove-back.up.railway.app
Brody
Brody2y ago
does your backend have a path registered for the root?
Nicolás Bonder
Nicolás BonderOP2y ago
no
Brody
Brody2y ago
whats a path i could hit that would tell me if its doing what it should
Nicolás Bonder
Nicolás BonderOP2y ago
In local enviroment, I use: http://localhost:3001/products and I see al the products
Brody
Brody2y ago
okay so it works then
Brody
Brody2y ago
Brody
Brody2y ago
now onto frontend
Nicolás Bonder
Nicolás BonderOP2y 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 BonderOP2y ago
Nicolás Bonder
Nicolás BonderOP2y ago
In build I see that
Brody
Brody2y 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 BonderOP2y ago
Like this?
Brody
Brody2y ago
so far so good, continue with the instructions
Nicolás Bonder
Nicolás BonderOP2y ago
YEAHHHHH!! It is working Thank you!!
Brody
Brody2y ago
woohoo
Want results from more Discord servers?
Add your server