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
Project ID:
c28866fd-5fa3-41e6-8ebd-1ab29b18f9c9
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
c28866fd-5fa3-41e6-8ebd-1ab29b18f9c9
your app needs to listen on host 0.0.0.0 and environment variable PORT
Sorry, it is the first time I do this deployment. Can you explain me a little more?
So, in the front-end I should add a env variable? PORT = 0.0.0.0:$PORT ?
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
I said add, because in the front-end I dont have a PORT variable
you dont need to add one, railway generates and injects it, and your app should listen on it
and if in the back-end, in the PORT variable, I use 0.0.0.0:$PORT, I get an error
^
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
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
No, I dont use it in railway, I use it in my app,
same thing
Sorry man, I dont understand. That is what I did
^
ok, I will remote it
^
This is what I dont understand. I understand I should remote it from railway, but I dont understand what else I should do
listen on the auto generated and injected PORT
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
send your repo please
this is the project: https://railway.app/project/c28866fd-5fa3-41e6-8ebd-1ab29b18f9c9
Railway
Railway
Railway is an infrastructure platform where you can provision infrastructure, develop with that infrastructure locally, and then deploy to the cloud.
that is not a github repository
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
I saw you were helping someone else with the same issue and he solved using a PORT variable.
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
.Hi rc, I tried what you said, but as soon as the deploy start, I get and error
This is what I did in railway
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}
);
});
});
}bruh
0.0.0.0 is not a port
remove the PORT from your service variables all together
Yes, you are right. I removed the PORT, but I keep seing: Failed to load resource: the server responded with a status of 503 ()
show screenshot of deploy logs
This is the back. I am starting again the front
hey hey, one service at a time okay
the backend says active, does it work?
Yes...or at least I think it works.
well check
test it
How?
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
Locally, I can see the app is working. Front and end are conecting
okay so the backend on railway is working? yes or no
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
^
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/
is that the backend
No, that is the front. The back end link is groove-back.up.railway.app
does your backend have a path registered for the root?
no
whats a path i could hit that would tell me if its doing what it should
okay so it works then
now onto frontend
In the front is where I see the error: Failed to load resource: the server responded with a status of 503 ()
In build I see that
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 changesLike this?
so far so good, continue with the instructions
YEAHHHHH!! It is working
Thank you!!
woohoo