7 months ago
I deployed my fullstack app to Railway by connecting my GitHub repo. The app consists of a Next.js frontend and a FastAPI backend located in the /api folder.
In the frontend, I send requests to FastAPI endpoints to trigger backend logic. This setup worked perfectly on Vercel. However, on Railway, I get a 404 error whenever the frontend tries to call a FastAPI endpoint.
It seems like only the Next.js app is being built and served - the FastAPI backend doesn't appear to be running. I also don't see any logs related to FastAPI during build or deployment, so I suspect the backend isn't starting at all.
Please help me understand how to correctly set up Railway to serve both the Next.js frontend and the FastAPI backend.
16 Replies
7 months ago
Do you have any logs shown in the backend? Does railway show it being online?
7 months ago
and here are the logs, but I am not sure if they are related to the backend:
Attachments
7 months ago
Are you able to from outside in request to the fastAPI backend? It looks conflicting, in the first attachment I see it online and in the second it looks as though it was SIGTERMed which is force closed
7 months ago
apologies for the confusion. the last screenshot is the old log. There are no logs at all in the Railway UI at the moment. I have the error that occurs in Network tab when hitting the backend
Attachments
7 months ago
Are you able to go look at the backend container and figure out which url it is on yourself? Not from the frontend. Poke around and query those to see if its truly a container issue or URL mismatch from frontend -> backend in prod.
7 months ago
I don't really get what do you mean by the backend container. Is it something that I can see in the Railway UI? I do not run frontend and backend separately. I deploy the repository at once
7 months ago
Can you share a bit more what your project structure looks like?
From my understanding its a "monorepo" situation where you have a folder specifically for your api living in an api folder in the project. Having a bit of trouble understanding how this deployment process looks? Is it a dockerfile? Railpacks? Docker compose? If its fastAPI I assume thats not embedded in nextjs so it would be a "dedicated backend" service right?
Basically, can I get a bit more info how you structured your project?
7 months ago
Yes, it's a Next.js app with a FastAPI backend living in the /api folder. From the frontend, I make POST requests to the FastAPI endpoints.
It’s kind of a monorepo setup, but to be honest, I didn’t set up any advanced deployment stuff like Docker or Railpacks. I just pushed it to GitHub and deployed it to Vercel, and it worked out of the box - both frontend and API routes were working fine there.
The only reason I am using Railway is because Vercel does not support "ffmeg". Now I’m trying to deploy it on Railway, however, I don’t fully understand how the deployment was handled under the hood in Vercel
7 months ago
Okay cool. I personally am not a big fan of monorepos. In that /api folder do you have its own mini "project"? Package.json the node modules its own entrypoint (main/index.js) etc.
If it does have its own self contained thing I personally recommend splitting it up into separate repos that way you can control updates individual for frontend/backend.
7 months ago
it has index.py which is the entypoint to fast api. thanks for suggestion, but I'll stick to monorepo as it's a pet project, and I don't want to spend extra time on it. Probably will stick to Vercel and try to solve the "ffmeg" issue there.
timtimer11
it has index.py which is the entypoint to fast api. thanks for suggestion, but I'll stick to monorepo as it's a pet project, and I don't want to spend extra time on it. Probably will stick to Vercel and try to solve the "ffmeg" issue there.
7 months ago
I dont know extensively but you might be able to set a second service from the folder of the project? Or set up a bash/sh script that starts both frontend and backend at the same time but thats uncharted waters for me.
timtimer11
it has index.py which is the entypoint to fast api. thanks for suggestion, but I'll stick to monorepo as it's a pet project, and I don't want to spend extra time on it. Probably will stick to Vercel and try to solve the "ffmeg" issue there.
7 months ago
You may not need to separate your code into different repositories. Set the start command correctly with the right path to the backend and frontend directories
7 months ago
You say it is not a monorepo but honestly it sounds a lot like one to me
Check these docs out https://docs.railway.com/guides/monorepo
7 months ago
If you are struggling with the set up for FastAPI this can help https://docs.railway.com/guides/fastapi