R
Railwayโ€ข6mo ago
What Colour?

Application failed to respond

I am using monorepo to deploy my app. So the nest js (back) is deployed successfully and works. The front is also deployed successfully, but when I try to open it, I am getting app failed to respond: 503. How can I fix this?
98 Replies
Percy
Percyโ€ข6mo ago
Project ID: 2db87ff7-665b-4dd6-b79c-b558b72d44f7
What Colour?
What Colour?โ€ข6mo ago
project/2db87ff7-665b-4dd6-b79c-b558b72d44f7 I tried to add host in start command, but still same:
maddsua
maddsuaโ€ข6mo ago
does your app listen on the same port as the PORT environment variable? if you can't pick that from the env, check what port it actually starts on an set PORT to that number
What Colour?
What Colour?โ€ข6mo ago
where can I check it?
maddsua
maddsuaโ€ข6mo ago
next should log that in deploy log when it's starting
What Colour?
What Colour?โ€ข6mo ago
do you mean this?
maddsua
maddsuaโ€ข6mo ago
yeah, your port here is 4200 I'm reading next docs right not and it seems that you'd need to pass port as a flag like this:
"start": "next start -p 8090",
"start": "next start -p 8090",
put the same port into env and it should work I'm just not sure if railway will unwrap env variable like gitlab does, if so, -p $PORT would also work
What Colour?
What Colour?โ€ข6mo ago
so where exactly should I put this? Could you please provide step by step?
maddsua
maddsuaโ€ข6mo ago
yeah, sure this is an api server but the logic is the same
What Colour?
What Colour?โ€ข6mo ago
so my varName is "start" and val: "next start -p 8090" ? or you mean I need to pass PORT: 4200?
maddsua
maddsuaโ€ข6mo ago
this variable needs to be set in the env here and then you start your server with -p 4200 just to make sure it always uses the same port oh I misread it again. it's not next, it's nest
What Colour?
What Colour?โ€ข6mo ago
But I have problem not with server, not the backend, only front has issues the angular app
maddsua
maddsuaโ€ข6mo ago
and you're using angular dev server in prod ???
What Colour?
What Colour?โ€ข6mo ago
the back works ok yes
maddsua
maddsuaโ€ข6mo ago
let's just start with adding PORT=4200 to the frontend's env
What Colour?
What Colour?โ€ข6mo ago
I'll try, give me a moment, thank you still same
maddsua
maddsuaโ€ข6mo ago
can you check if it still starts on the same port? never actually worked with angular tbh
What Colour?
What Colour?โ€ข6mo ago
maddsua
maddsuaโ€ข6mo ago
well I've seen some dev servers refuse to serve anything outside of localhost, maybe it's the case do you absolutely need to use DEV server?
What Colour?
What Colour?โ€ข6mo ago
what else can I use? what do u mean?
maddsua
maddsuaโ€ข6mo ago
build it for prod? doesn't it work that way?
What Colour?
What Colour?โ€ข6mo ago
I'm sorry, can you explain what should I change in package.json?
maddsua
maddsuaโ€ข6mo ago
build:client will, well, build the app for the production use, but after that you'd need to tell railway to pick that up lemme check the docks real quick I'm assuming the build produces a bunch of html, css and js files can you run build locally and show me what does it produce?
What Colour?
What Colour?โ€ข6mo ago
sure
maddsua
maddsuaโ€ข6mo ago
right, and the directory appears to be dist/apps/client is that correct?
What Colour?
What Colour?โ€ข6mo ago
+
maddsua
maddsuaโ€ข6mo ago
ok, trying to make static server work, I'll be back in a few minutes I found a similar project of mine, testing with it
What Colour?
What Colour?โ€ข6mo ago
ok, I'll wait, thank you
maddsua
maddsuaโ€ข6mo ago
add this dockerfile to the directory from which you deploy the frontend the custom start command can also be removed the idea here is that it copies all the build output to the container and starts nginx oh and set the PORT to 80 that's the default setting nginx is a web server in this context
What Colour?
What Colour?โ€ข6mo ago
but now both failes: back and front: Just removed start command from front, waiting for deploy also error
maddsua
maddsuaโ€ข6mo ago
oh is service root directory set for both services? https://docs.railway.app/guides/monorepo a dockerfile in frontend should not affect backend that's the idea
What Colour?
What Colour?โ€ข6mo ago
I put dockerfile to the whole nx project
maddsua
maddsuaโ€ข6mo ago
yeah, this isn't gonna work
What Colour?
What Colour?โ€ข6mo ago
should I put the docker only to apps/client?
maddsua
maddsuaโ€ข6mo ago
what's the project structure? probably you can just do that
What Colour?
What Colour?โ€ข6mo ago
maddsua
maddsuaโ€ข6mo ago
do client and server have their own package.jsons? I'm just thinking of a way to separate them without breaking anything
What Colour?
What Colour?โ€ข6mo ago
this is after moving docker to client:
maddsua
maddsuaโ€ข6mo ago
damn my brain really needs to adapt to github deployments ๐Ÿ˜€ I forgot to add build step does the server deploy tho?
What Colour?
What Colour?โ€ข6mo ago
yes, but still same issue and i did not removed the start commands Why my server is running well, but the angular front can't work normally, this is so weird
maddsua
maddsuaโ€ข6mo ago
idk why is it running actually, but with the frontend it's kinda expected you either need to have a node server (not dev) or to use nginx/some other web server ok, I think I have a dockerfile which would actually work but we still need to figure out how to only trigger the frontend
What Colour?
What Colour?โ€ข6mo ago
to trigger only a front we need to use start commands for sure i think
maddsua
maddsuaโ€ข6mo ago
I'd say that the project structure needs to be adjusted but for now can we try just making the frontend run?
FROM node:20 as builder
WORKDIR /app
COPY . .
RUN npm ci
RUN npm run build:client

FROM nginx:alpine
COPY --from=builder /app/dist/apps/client /usr/share/nginx/html
FROM node:20 as builder
WORKDIR /app
COPY . .
RUN npm ci
RUN npm run build:client

FROM nginx:alpine
COPY --from=builder /app/dist/apps/client /usr/share/nginx/html
What Colour?
What Colour?โ€ข6mo ago
but this is main structure made by nx
maddsua
maddsuaโ€ข6mo ago
the new dockerfile I hope it will work try placing it in project root backend will fail for sure but frontend should come to life build command is not needed with the dockerfile
What Colour?
What Colour?โ€ข6mo ago
same issue and deploy success bug give errors:
maddsua
maddsuaโ€ข6mo ago
naaah it's not an error it should actually work now did u set PORT to 80?
What Colour?
What Colour?โ€ข6mo ago
oh wait, I removed port
maddsua
maddsuaโ€ข6mo ago
I mean I see the same red console, it's just a bug
What Colour?
What Colour?โ€ข6mo ago
let me check with port 80 nah, still the same( wait, works
maddsua
maddsuaโ€ข6mo ago
yey
What Colour?
What Colour?โ€ข6mo ago
ohhh, now it works, but my back is not deployed ๐Ÿ˜„
maddsua
maddsuaโ€ข6mo ago
well, at least not you know that it's possible ๐Ÿ™‚ idk really what to actually do next I'd try to separate them into different directories somehow
What Colour?
What Colour?โ€ข6mo ago
but this just change my problem from front to back) anyways thx for your try
maddsua
maddsuaโ€ข6mo ago
so that railway won't even touch the other part
What Colour?
What Colour?โ€ข6mo ago
maybe we can pass some variables? back and front and then use it in setting files? like PORT: 80 but for which part of app to use
maddsua
maddsuaโ€ข6mo ago
can you show me the backend error log?
What Colour?
What Colour?โ€ข6mo ago
I don't have any variables in server, and also I have build and start commands set in
maddsua
maddsuaโ€ข6mo ago
the thing is that as the dockerfile is placed in the root, it is used for the both services and it's not gonna work it will work for sure if you could somehow split them and give each it's own dockerfile or build command or whatever
What Colour?
What Colour?โ€ข6mo ago
is it ok when I refresh my front page it returns: but when I start it first it works
maddsua
maddsuaโ€ข6mo ago
oh that's a config issue with nginx. it even was described here the config
What Colour?
What Colour?โ€ข6mo ago
where should I put it? apps/client?
maddsua
maddsuaโ€ข6mo ago
right next to dockerfile I'm trying to make it work in my test app
What Colour?
What Colour?โ€ข6mo ago
ohh, oke btw config did not solve refresh issue
maddsua
maddsuaโ€ข6mo ago
it's not linked yet and it's broken ๐Ÿคฃ seems to work now ๐Ÿ‘€
What Colour?
What Colour?โ€ข6mo ago
should I also put variable port 80 to my back? back build successfully, but not working at all oh wait, it also crashed. not success)
maddsua
maddsuaโ€ข6mo ago
sorry but I don't think I can do anything here to make railway see the difference between them except for actually converting project to a monorepo, where frontend and backend are in different folders and have 2 separate package.jsons
What Colour?
What Colour?โ€ข6mo ago
how can I do that? but nx is also monorepot thing My project is monorepo
maddsua
maddsuaโ€ข6mo ago
thonk
What Colour?
What Colour?โ€ข6mo ago
Nx
Nx: Smart Monorepos ยท Fast CI
Nx is a build system with built-in tooling and advanced CI capabilities. It helps you maintain and scale monorepos, both locally and on CI.
What Colour?
What Colour?โ€ข6mo ago
btw the config file is fixing issue now ๐Ÿ™‚
maddsua
maddsuaโ€ข6mo ago
idk really I've never worked with this one and generally I'm not a fan of so called build systems you know more about it than I do for sure
What Colour?
What Colour?โ€ข6mo ago
anyway thank you for your try)) I will wait, maybe someone can help me with this one. Thanks @madhdsua I almost fixed it) I renamed dockerfile to dockerfile.front, and using docker file only in front as variablName now back works and front also. But front has some issues
maddsua
maddsuaโ€ข6mo ago
Interesting
What Colour?
What Colour?โ€ข6mo ago
when I click create acc: but if I run locally and click creat acc, works fine
maddsua
maddsuaโ€ข6mo ago
prob need more config fiddling yeeeeah it is
What Colour?
What Colour?โ€ข6mo ago
this is front deploy: now it does not even want to run at all, I mean front
maddsua
maddsuaโ€ข6mo ago
yeah I see it same with mine xD
What Colour?
What Colour?โ€ข6mo ago
honestly I got no idea about this errors
maddsua
maddsuaโ€ข6mo ago
I have. it returns wrong content-type header I thing I have it under control
Solution
maddsua
maddsuaโ€ข6mo ago
maddsua
maddsuaโ€ข6mo ago
just added a line that included proper types now it's good
What Colour?
What Colour?โ€ข6mo ago
still same
maddsua
maddsuaโ€ข6mo ago
it may take a few minutes to propagate
What Colour?
What Colour?โ€ข6mo ago
is this space will not cause an issue?
maddsua
maddsuaโ€ข6mo ago
nah it's not python
What Colour?
What Colour?โ€ข6mo ago
ohh, ok)
maddsua
maddsuaโ€ข6mo ago
can u give me the fronted url real quick? imma curl it
maddsua
maddsuaโ€ข6mo ago
try clearing browser's cache I see all correct headers now
What Colour?
What Colour?โ€ข6mo ago
almost works, cleared a cache, but now when I go to users page for example same error
maddsua
maddsuaโ€ข6mo ago
weird... and what's going on in the network tab?
What Colour?
What Colour?โ€ข6mo ago
maddsua
maddsuaโ€ข6mo ago
dark magic I guess u tried reloading page with Ctrl+F5, right?
What Colour?
What Colour?โ€ข6mo ago
+
maddsua
maddsuaโ€ข6mo ago
how does it even do that ๐Ÿ’€
What Colour?
What Colour?โ€ข6mo ago
ohhh oke, in incognito mode it works great, maybe this is my app auth.guard issue Thanks a lot my mate)) I hope it will work in future. Now it works great, thanks mate)
maddsua
maddsuaโ€ข6mo ago
you're welcome I'd appreciate it if you mark this issue as solved this thing