Railway+fastapi help needed
ahmad55666
FREEOP

10 months 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?

Closed$10 Bounty

20 Replies

andresndp
FREE

10 months 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

10 months 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

10 months ago

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


ahmad55666
FREEOP

10 months ago

it is private broo bcz it source code


oranuare
PRO

10 months 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

10 months ago

let me tell you w8 a bit


ahmad55666
FREEOP

10 months ago

Here’s one example route from my code:

In app.py:

from backend.routes import social_webhooks

app.include_router(social_webhooks.router, prefix="/api/social")

Example route inside social_webhooks.py:

@router.get("/test")

async def test_webhook_router():

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

10 months 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

10 months 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

10 months ago

@ranuare @Railway


oranuare
PRO

10 months 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

10 months ago

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

1433695325369143427


ahmad55666
FREEOP

10 months ago

already configured

1433696436859699220


ahmad55666
FREEOP

10 months ago

@ranuare @Railway


oranuare
PRO

10 months ago

Still not working?


oranuare
PRO

10 months ago

Do you have the health path inside app.py?


ahmad55666
FREEOP

10 months ago

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


ahmad55666
FREEOP

10 months ago

i have configured them for frontend


ahmad55666
FREEOP

10 months ago

sorry for your wastage of time


oranuare
PRO

10 months ago

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


Welcome!

Sign in to your Railway account to join the conversation.

Loading...