njgibbon / nicks-cors-test

Simple HTML & JS Tool to quickly test CORS locally.
125 stars 63 forks source link

facing issue of CORS policy in my flask POST API #1

Closed ssaurav-1987 closed 3 years ago

ssaurav-1987 commented 3 years ago

Hi @njgibbon,

Thanks for this tool that help me to test my API whether it supports CORS policy or not. I am facing one issue in my flask API. I have created a POST request in Flask and internally I am calling another REST API GET request to fetch the data from another server, and due to calling that internal GET request to fetch data your tool is saying

Access to XMLHttpRequest at 'http://127.0.0.1:5000/wlc/' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

As in my POST request code I have added CORS but for external GET API how I will have to support CORS.

njgibbon commented 3 years ago

Hey,

CORS is always enabled by the server not the client. So in your case it seems as though you haven't enabled CORS on your Flask App.

This sounds like your issue https://stackoverflow.com/questions/25594893/how-to-enable-cors-in-flask

The GET request internal to your App should be unaffected by CORS because the python library will have a valid user agent. CORS is generally only applied to code that is executed in the browser.

njgibbon commented 3 years ago

Closing this as an answered question. All the best with your work 🙂 .