FastAPI backend returns 502
jamieziglerx2-art
FREEOP

10 days ago

Fast api returns 502on all routes. Container starts successfully, health check passes, port is 8000

Solved$10 Bounty

Pinned Solution

Something I'd try is to set your FastAPI to listen to an arbitrary port number (eg, 3000), and change the URL to map to that port as well.

8 Replies

Status changed to Open Railway 10 days ago


Make sure the port your URL is mapped to is the same port your application is listening to (8000 it seems?).


jamieziglerx2-art
FREEOP

10 days ago

Port is already set to 8000

Attachments


For this error, you'll need to add CORS headers to allow your frontend URL to access the API.


jamieziglerx2-art
FREEOP

10 days ago

When I add CORSMiddleware to my FastAPI app it causes 502 errors. My frontend is at https://gregarious-celebration-production-d2a0.up.railway.app and my backend is at https://dirtbike-tuning-hub-production.up.railway.app. How do I add CORS headers without breaking the app


Something I'd try is to set your FastAPI to listen to an arbitrary port number (eg, 3000), and change the URL to map to that port as well.


jamieziglerx2-art

When I add CORSMiddleware to my FastAPI app it causes 502 errors. My frontend is at <https://gregarious-celebration-production-d2a0.up.railway.app> and my backend is at <https://dirtbike-tuning-hub-production.up.railway.app>. How do I add CORS headers without breaking the app

Cors middleware is not related to the 502 errors you're getting. It mostly stems from mapping your URL to a port your app isn't listening on.

If your app is already listening on port 8000, map your URL to 8000 as well. You can find it in Service Settings > Networking.


jamieziglerx2-art
FREEOP

10 days ago

I changed the port to 3000 and it is running the backend now. Not sure if this is a true fix but its a move in the right direction


The 502 was caused by a port mismatch. The CORS was a side effect of the port mismatch.


Status changed to Solved 0x5b62656e5d 10 days ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...