Azure Functions – Access has been blocked by CORS policy
IT Management

Azure Functions – Access has been blocked by CORS policy


Ever ything begun by attempting to over-engineer things with an Azure Function. And after that it would not work! This post is primarily for me so that I can discover this things later on when I undoubtedly struck the very same CORS concern.

I had actually gone through the entire Microsoft tutorial for JavaScript Azure Functions, and after that evaluated my Azure Function in your area and remote by means of Visual Code’s integrated system screening. When I attempted to get my application’s JavaScript to call the function, I was all of a sudden obstructed by a CORS concern.

The Code

In my JavaScript, I have an extremely easy bring call to my Azure Function:

 bring('

The Mistake

Invoking this resulted in the following mistake:

 Access to bring at' from origin' has actually been obstructed by CORS policy: No 'Access-Control-Allow-Origin' header exists on the asked for resource. If a nontransparent action serves your requirements, set the demand's mode to 'no-cors' to bring the resource with CORS handicapped.

The Repair

A couple of Google outcomes later on, I discovered this StackOverflow concern:

The response here validated that this is a CORS setup on the Azure side that requires to be carried out in the Website. From Visual Code I right-clicked on my Azure function and chosen Open in website:

This popped open the Azure Website to the appropriate function in my membership. On the left pane, I then scrolled down to the API area and chosen CORS.

A CORS management panel loads up where I can go into enabled origins:

From here I might include my regional advancement URL and whatever worked! HOORAY!
Undoubtedly, later I will need to include any staging or production hosting domains too, however for now, I can move on.


Source link