azure - 无法在 Azure Functions Linux 消耗计划上编辑 CORS

标签 azure azure-functions

我已经用 Python 实现了一个 Azure 函数,该函数仅适用于 Azure Linux 服务器。使用 Visual Studio Code,我设法在本地运行这些函数,并使用 postman 执行测试,请求成功运行。我还使用 Visual Studio Code 将这些函数部署到 Azure,并再次使用 Postman 测试了公共(public) REST API 主机,它成功了。

问题是通过我的 Web 应用程序调用此 API,该应用程序返回了 CORS 错误。 我知道这是正常的,因为我没有通过 Azure 面板在 CORS 中设置允许所有 (*) 属性。基本上,因为 CORS 被阻止:

enter image description here

当我点击时,我收到以下警告:

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

我尝试在 python 函数中添加 header ,例如:

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

然后在响应中:

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

但仍然收到 CORS 错误。

最佳答案

尝试使用 Azure CLI 启用 CORS ,

az functionapp cors add --allowed-origins
                        [--ids]
                        [--name]
                        [--resource-group]
                        [--slot]
                        [--subscription]

关于azure - 无法在 Azure Functions Linux 消耗计划上编辑 CORS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57288228/

相关文章:

postgresql - Azure Function 创建了太多与 PostgreSQL 的连接

c# - Azure 函数 - 获取配置推荐实践

node.js - 在两个文件之间传递连接 - azure 函数

azure - 事件中心检查点的 Azure Function webjobs 存储成本较高

azure - 获取用户委派 key 后如何创建用户委派 SAS

node.js - 使用 node.js 在特定延迟后从 Azure ServiceBus 主题发送消息

azure - MS Azure/代码优先 : Login failed for user

azure - 如果客户端未发送,如何在 APIM 入站策略中获取/设置 Traceparent header ?

java - 在 KeyVaultClient java 中将代理设置为 AuthenticationContext 没有效果

azure - 停止/终止正在运行的 Azure 函数