Railway+fastapi help needed

ahmad55666
FREEOP

13 days ago

Need help with Railway + FastAPI
My app works fine on localhost — all routes like /webhook work.
But on Railway, only /health works — everything else shows 404 Not Found.

No errors in logs, app starts fine.
I’m using uvicorn main:app.

Maybe the railway.toml or start command is wrong?
Example:

uvicorn main:app --host 0.0.0.0 --port $PORT

Any idea why only /health works?

$10 Bounty

1 Replies

andresndp
FREETop 10% Contributor

13 days ago

The fact that /health works confirms the app is running and accessible, so this is an application-level routing issue, not a Railway platform problem.

Is your FastAPI app using any routers or subpath mounting? If routes are mounted on a subpath (like /api/v1/webhook), you need to access them accordingly.


ahmad55666
FREEOP

12 days ago

i am trying but to acess with like .api/v1 etc but still not working and showing the not found even its works perfectly on local host


oranuare
PRO

12 days ago

Do you have a link to your repo or is it private?


ahmad55666
FREEOP

12 days ago

it is private broo bcz it source code


oranuare
PRO

12 days ago

I understand, is there a way you can show us one route as an example and the configuration you have to add that route to the main fastapi app


ahmad55666
FREEOP

12 days ago

let me tell you w8 a bit


ahmad55666
FREEOP

11 days ago

Here’s one example route from my code:

In app.py:

from backend.routes import socialwebhooks app.includerouter(social_webhooks.router, prefix="/api/social")

Example route inside social_webhooks.py:

@router.get("/test")
async def testwebhookrouter():
return {"status": "success", "message": "Social webhooks router is loaded!"}

Locally this works fine at:
http://127.0.0.1:8000/api/social/test

But on Railway, I get a 404 at:
https://.up.railway.app/api/social/test

Only /health works on Railway.
Can you please confirm if I need to adjust ROOT_PATH or prefix handling on Railway?
@ranuare @Railway


oranuare
PRO

11 days ago

Can you try to use the prefix inside social_webhooks, like this:

router = APIRouter(
prefix="/api/social"
)

Instead of adding it in the app.py


ahmad55666
FREEOP

11 days ago

Hey, I tried moving the prefix inside social_webhooks.py like this:

router = APIRouter(prefix="/api/social")

but it still didn’t work.
Only /health route works on Railway — all other routes (like /api/social/webhook) give 404.
My main file is app.py (not main.py).


ahmad55666
FREEOP

11 days ago

@ranuare @Railway


oranuare
PRO

11 days ago

If you go to your fastapi service, click on the last deployment and go to details tab you can see what railpack is using


oranuare
PRO

11 days ago

Check if its using the app.py as the main file, if not, you can add a custom start command

1433695325369143600


ahmad55666
FREEOP

11 days ago

already configured

1433696436859699200


ahmad55666
FREEOP

11 days ago

@ranuare @Railway


oranuare
PRO

11 days ago

Still not working?


oranuare
PRO

11 days ago

Do you have the health path inside app.py?


ahmad55666
FREEOP

11 days ago

bro i understand why its happening its my own fault like for accesing through url


ahmad55666
FREEOP

11 days ago

i have configured them for frontend


ahmad55666
FREEOP

11 days ago

sorry for your wastage of time


oranuare
PRO

11 days ago

No worries! To me it was weird it wasn't working haha