简体   繁体   English

本地主机上的 Azure 功能代理 404

[英]Azure Functions Proxy 404 on localhost

I have an Azure Function App with a function at the URL http://localhost:7072/api/create-room along with other functions. I have an Azure Function App with a function at the URL http://localhost:7072/api/create-room along with other functions. This particular function is a HTTPTrigger with allowed anonymous access and accepts the GET verb:这个特殊的 function 是一个允许匿名访问的HTTPTrigger并接受GET动词:

[HttpTrigger(AuthorizationLevel.Anonymous, "get")]

Along with that, I have a separate function app that hosts only a proxies.json file and serves only as a functions proxy.除此之外,我还有一个单独的 function 应用程序,它只托管一个proxies.json文件并且仅用作函数代理。 My proxies function is running on port 7071 locally.我的代理 function 在本地端口7071上运行。

My proxies file currently looks like this:我的代理文件目前如下所示:

{
    "$schema": "http://json.schemastore.org/proxies",
    "proxies": {
      "chatNegotiate": {
        "matchCondition": {
          "route": "/api/chat/negotiate",
          "methods": [
            "POST"
          ]
        },
        "backendUri": "%chat_api%/api/BeginNegotiate"
      },
      "chatMessages": {
        "matchCondition": {
          "route": "/api/chat/messages",
          "methods": [
            "POST"
          ]
        },
        "backendUri": "%chat_api%/api/PostMessage"
      },
      "createRoom": {
        "matchCondition": {
          "route": "/api/create-room",
          "methods": [
            "GET"
          ]
        },
        "backendUri": "%session_api%/api/CreateRoom"
      }
    }
}

When both of these function apps are deployed to Azure, everything works like a dream.当这两个 function 应用程序都部署到 Azure 时,一切都像做梦一样。 I can make requests, they're forwarded on, requests come back.我可以提出请求,它们被转发,请求回来。 It's all glorious.这一切都是光荣的。

However, when I run these functions locally, the request is never forwarded on from the proxy, with the proxy returning a 404. I can hit the function on the other function app running locally on 7072 directly and all is well there, but not at all when I got via the proxy.但是,当我在本地运行这些功能时,请求永远不会从代理转发,代理返回 404。我可以直接在7072上本地运行的另一个 function 应用程序上点击 function,一切都很好,但不是所有当我通过代理。

The proxy itself returns:代理本身返回:

[30/05/2020 18:24:30] Host lock lease acquired by instance ID '0000000000000000000000002D5B6BEA'.
[30/05/2020 18:24:34] Executing HTTP request: {
[30/05/2020 18:24:34]   "requestId": "9004b8e2-f208-4a98-8b48-6f85bca41281",
[30/05/2020 18:24:34]   "method": "GET",
[30/05/2020 18:24:34]   "uri": "/api/create-room"
[30/05/2020 18:24:34] }
[30/05/2020 18:24:34] Executed HTTP request: {
[30/05/2020 18:24:34]   "requestId": "9004b8e2-f208-4a98-8b48-6f85bca41281",
[30/05/2020 18:24:34]   "method": "GET",
[30/05/2020 18:24:34]   "uri": "/api/create-room",
[30/05/2020 18:24:34]   "identities": [],
[30/05/2020 18:24:34]   "status": 404,
[30/05/2020 18:24:34]   "duration": 15
[30/05/2020 18:24:34] }

From examples I've looked at such as https://chsakell.com/2019/02/03/azure-functions-proxies-in-action/ , this should be working fine.从我看过的例子来看,例如https://chsakell.com/2019/02/03/azure-functions-proxies-in-action/ ,这应该可以正常工作。

Any suggestions?有什么建议么? Thanks in advance for any help you can provide!提前感谢您提供的任何帮助!

I've solved this after all.毕竟我已经解决了这个问题。

proxies.json isn't set to copy to the output directory by default. proxies.json 默认未设置为复制到 output 目录。

You need to ensure that it's set to copy always .您需要确保将其设置为始终复制

In Visual Studio:在 Visual Studio 中:

Right click proxies.json > click properties > Set Copy to output directory to Copy Always .右键单击proxies.json > 单击属性> 将Copy to output 目录设置为Copy Always

In Visual Studio Code (and other editors): Open ProjectName.csproj and add an entry to always copy proxies.json to output directory.在 Visual Studio Code(和其他编辑器)中:打开ProjectName.csproj并添加一个条目以始终将proxies.json复制到 output 目录。

<ItemGroup>
  <None Update="proxies.json">
    <CopyToOutputDirectory>Always</CopyToOutputDirectory>
  </None>
</ItemGroup>

This solved the problem with the 404 on my local instance of the function app proxy.这解决了我的 function 应用程序代理的本地实例上的 404 问题。 In local.settings.json add this to Values:在 local.settings.json 中将其添加到值:

"AZURE_FUNCTION_PROXY_DISABLE_LOCAL_CALL": true, “AZURE_FUNCTION_PROXY_DISABLE_LOCAL_CALL”:是的,

Credit: https://chsakell.com/2019/02/03/azure-functions-proxies-in-action/信用: https://chsakell.com/2019/02/03/azure-functions-proxies-in-action/

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

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