简体   繁体   English

为Azure功能本地主机配置CORS

[英]Configure CORS for Azure Functions Local Host

I'm testing an Azure Functions app locally with the Azure Functions CLI tooling. 我正在使用Azure Functions CLI工具在本地测试Azure Functions应用程序。 Is there any way I can configure CORS settings for the local host? 有什么办法可以为本地主机配置CORS设置吗?

You can start the host like this 你可以像这样启动主机

func host start --cors *

You can also be more specific and provide a comma delimited list of allowed urls 您还可以更具体,并提供逗号分隔的允许网址列表

More here: https://github.com/Azure/azure-webjobs-sdk-script/issues/1012 更多信息: https//github.com/Azure/azure-webjobs-sdk-script/issues/1012

You can configure CORS in the local settings file local.settings.json : 您可以在本地设置文件 local.settings.json配置CORS:

{
  "Values": {
  },
  "Host": {
    "CORS": "*"
  }
}

Settings in the local.settings.json file are used only when you're running projects locally local.settings.json文件中的设置仅在本地运行项目时使用

If you're having issues passing in the params via Visual Studio's Debug's "Application Arguments". 如果您在通过Visual Studio的Debug的“应用程序参数”传递参数时遇到问题。 This is how to pass the params from the command line: 这是如何从命令行传递参数:

1) Open an ordinary command prompt. 1)打开普通的命令提示符。

2) cd to your solution's compiled dll, ie "Your Solution Path"\\bin\\Debug\\netstandard2.0 2)cd到你的解决方案的编译dll,即“你的解决方案路径”\\ bin \\ Debug \\ netstandard2.0

3) start the Azure function runtime from the command line, ie: 3)从命令行启动Azure函数运行时,即:

dotnet "C:\Users\USER\AppData\Local\Azure.Functions.V2.Cli\func.dll" host start --port 7071 --cors * --pause-on-error 

4) To debug in Visual Studio, Debug->Attach to Process.. and attach to the donet.exe that will be running. 4)在Visual Studio中调试,调试 - >附加到进程..并附加到将运行的donet.exe。

Hope that helps prevent someone from banging their head too much... 希望有助于防止有人过多地敲打他们的头脑......

Another easy way to configure CORS on Azure Functions is to use Azure Portal, 在Azure Functions上配置CORS的另一种简单方法是使用Azure Portal,

1- Go to the Function App Settings in Azure Portal 1-转到Azure门户中的功能应用程序设置

在此输入图像描述

2 - Click on CORS and add your local host url 2 - 单击CORS并添加本地主机URL

在此输入图像描述

And there you have it!! 你有它!

Hope this helps someone. 希望这有助于某人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM