CORS with Azure function from localhost (not CLI)
To set CORS working locally when you are not using CLI and you are using Visual Studio/ VS Code - you need to add local.settings.json file into your project if it's not there.
Make sure "Copy to output directly" set to "copy if newer"
Then in your "local.settings.json" you can add CORS": "*"
like so:
{ "IsEncrypted": false, "Values": { }, "Host": { "LocalHttpPort": 7071, "CORS": "*" }}
More info:https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local
We got it working. It was a configuration in our Azure function. You go to "Platform Features" then "CORS". We added http://localhost:8080 to the list of "Allowed Origins" and then everything worked.
Elaboration For Production Environment Issues
I was having a problem on localhost, and on production (firebase hosted), trying to get my JavaScript Web app to interact with an Azure Function.
Cross-Origin Resource Sharing (CORS) allows JavaScript code running in a browser on an external host to interact with your backend.
In Azure Functions, click the features tab, and click the CORS block under "networking and security".
Add your domain as an allowed origin and hit save. This will fix the issue.
For v3+
the following works:
p.s. note that location of Hosts
is on the same level as Values
and not under it (as in the answer by azadeh-khojandi https://stackoverflow.com/a/48069299/2705777)
Configure CORS in the local settings file local.settings.json
:
{ "Values": { }, "Host": { "CORS": "*" }}