【问题标题】:How to configure CORS in Azure?如何在 Azure 中配置 CORS?
【发布时间】:2022-01-12 19:53:28
【问题描述】:

我的 Azure 函数在本地运行,我正在寻找一种可以在本地设置 CORS 的方法。

我通过了下面的 Microsoft Documentation 但无法实现。

【问题讨论】:

标签: azure azure-functions


【解决方案1】:

在您的机器本地运行的函数应用中启用 CORS

打开函数应用根文件夹中的local.settings.json 文件(如果不存在,则创建一个。see)。

然后添加(或附加)以下内容以允许所有:

{
    //Your other configs here
    "Host": {
        "CORS": "*"
    }
}

或者,如果您有特定的 URL 和端口想要加入白名单

{
    //Your other configs here
    "Host": {
        "CORS": "http://localhost:12345"
    }
}

在 Azure 中托管的函数应用中启用 CORS:

通过 azure 门户转到您的函数应用实例,然后单击 API 部分下的“CORS”左侧菜单选项。

您可以在此处为您的函数应用配置 CORS。

Azure 文档:https://docs.microsoft.com/en-us/azure/azure-functions/functions-how-to-use-azure-function-app-settings?tabs=portal#cors

【讨论】:

    猜你喜欢
    • 2014-07-09
    • 2015-04-20
    • 1970-01-01
    • 1970-01-01
    • 2017-05-12
    • 2015-07-15
    • 2017-10-30
    • 2021-04-17
    • 2021-10-28
    相关资源
    最近更新 更多