Configure CORS for Azure Functions Local Host

半腔热情 提交于 2020-01-22 13:35:50

问题


I'm testing an Azure Functions app locally with the Azure Functions CLI tooling. Is there any way I can configure CORS settings for the local host?


回答1:


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




回答2:


You can configure CORS in the local settings file local.settings.json:

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

Settings in the local.settings.json file are used only when you're running projects locally




回答3:


If you're having issues passing in the params via Visual Studio's Debug's "Application Arguments". This is how to pass the params from the command line:

1) Open an ordinary command prompt.

2) cd to your solution's compiled dll, i.e. "Your Solution Path"\bin\Debug\netstandard2.0

3) start the Azure function runtime from the command line, i.e.:

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.

Hope that helps prevent someone from banging their head too much...




回答4:


Another easy way to configure CORS on Azure Functions is to use Azure Portal,

1- Go to the Function App Settings in Azure Portal

2 - Click on CORS and add your local host url

And there you have it!!

Hope this helps someone.



来源:https://stackoverflow.com/questions/42378987/configure-cors-for-azure-functions-local-host

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!