10 days ago
Fast api returns 502on all routes. Container starts successfully, health check passes, port is 8000
Pinned Solution
10 days ago
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
10 days ago
Make sure the port your URL is mapped to is the same port your application is listening to (8000 it seems?).
10 days ago
For this error, you'll need to add CORS headers to allow your frontend URL to access the API.
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
10 days ago
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
10 days ago
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.
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
10 days ago
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
