Blocked by CORS Policy but I allow all URLs
hobbie71
FREEOP

6 months ago

Github repository:
https://github.com/hobbie71/MakeCode-Arcade-Sprite-Generator

Project ID:
3a021bd1-db69-4e85-9cdc-24f00ad39bde

Hey!

So I have a react frontend. just a static site that's working.

And I have a FastAPI backend.

Every time I go to my frontend URL, go through my app, and do something that calls an API from my backend, I get this error:

...has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

To debug this, I went ahead and added this to my ENV variables

CORS_ORIGINS="["*"]"

and somehow, I still get this errors. I'm assuming it's something wrong with my backend code? When I run this in a dev envornment, it works fine even when adding specific urls like this:

CORS_ORIGINS="["http://localhost:3000", "http://localhost:5173"]"

So, I'm not sure why I'm getting this error. I would appreciate any help.

Even debugging tips or possible causes of the issue would be a huge help.

I've been at this for too many hours, so I'm going to go to bed.

Thank you for reading this post and taking the time to help me find a solution.

$10 Bounty

6 Replies

Railway
BOT

6 months ago


irazvan2745
FREE

6 months ago

For some reason thats just how railway is, i had the same issues with my Hono backend app


luksuz
HOBBY

6 months ago

Hey, please make sure you are sending a HTTPS request, not HTTP to your railway backend :)


irazvan2745

For some reason thats just how railway is, i had the same issues with my Hono backend app

hobbie71
FREEOP

6 months ago

Hey irazvan,

So there's no way to fix it?

Railway just isn't compatible with FastAPI and Hono?


luksuz

Hey, please make sure you are sending a HTTPS request, not HTTP to your railway backend :)

hobbie71
FREEOP

6 months ago

Hey Luksuz,

I was sending the request through the generated link for my front-end.

You know the railway.app url.

When I check, it is an HTTPS URL. Also, from the error I get in the console, it shows me the URL which also include HTTPS in the front of the url.


hobbie71

Hey irazvan,So there's no way to fix it?Railway just isn't compatible with FastAPI and Hono?

irazvan2745
FREE

6 months ago

its just CORS being special and i think railway forces you to not use * in cors


Status changed to Open brody 6 months ago


Loading...