Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't edit CORS on Azure Functions Linux Consumption Plan

I have Implemented an Azure Function in Python which only works on Azure Linux servers. Using Visual Studio Code I managed to run the functions locally and performed the testing with postman the requests worked successfully. I have also deployed the functions to Azure using Visual Studio Code and again tested the public REST API host with Postman and it worked.

The problem was calling this API through my web application which returned CORS error. I know this is normal because I didn't set allow all (*) property in the CORS through Azure panel. Basically, because the CORS is blocked:

enter image description here

When I click I get the following warning:

This feature is not supported for Linux apps on a Consumption plan

I have tried adding the headers inside my python function like:

 headers  = {
        "Access-Control-Allow-Origin": "*",
        "Access-Control-Allow-Methods": "GET, POST, OPTIONS"
    }

And then in the response:

return func.HttpResponse(f"{result}",headers=headers)

But still getting the CORS error.

like image 531
Programmer Man Avatar asked Oct 15 '22 12:10

Programmer Man


1 Answers

Try enabling CORS with the Azure CLI,

az functionapp cors add --allowed-origins
                        [--ids]
                        [--name]
                        [--resource-group]
                        [--slot]
                        [--subscription]
like image 141
Sajeetharan Avatar answered Oct 20 '22 23:10

Sajeetharan