corydolphin / flask-cors

Cross Origin Resource Sharing ( CORS ) support for Flask
https://flask-cors.corydolphin.com/
MIT License
867 stars 140 forks source link

CORS partially fails when making requests with axios in React #328

Open AdolfoRoquero opened 1 year ago

AdolfoRoquero commented 1 year ago

I am using React for the front-end running on 'http://localhost:3000' and Flask for the backend running on http://127.0.0.1:5000. I am running into the following error Access to XMLHttpRequest at 'http://127.0.0.1:5000/manager/personnel' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request. I am using the following code to set up CORS:

cors = CORS(origins=['http://localhost:3000', 'http://127.0.0.1:3000','http://localhost:5000'])
...

def create_app(config_class=Config):
    app = Flask(__name__)
    ...
    cors.init_app(app)

I also tried using CORS at the blueprint level unsuccessfully. What is most surprising is that some requests to the backend still succeed.

Someone had a similar issue on StackOverflow but never got a response: https://stackoverflow.com/questions/73665955/why-do-i-get-a-cors-error-with-react-axios-and-flask

Aadesh-Baral commented 12 months ago

Does this URL http://127.0.0.1:5000/manager/personnel exist on your backend app? Can you verify it's http://127.0.0.1:5000/manager/personnel without / at the end ?

JacobDel commented 11 months ago

same problem, with or without "/" at the end

terrynguyen255 commented 11 months ago

Seems related to this unresolved issue. I will update this comment if I can figure it out.