1
votes

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:

[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. My proxies function is running on port 7071 locally.

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. 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.

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.

Any suggestions? Thanks in advance for any help you can provide!

2
Have you updated your local.settings.json in the local? – Vivek Patel
If you are getting a 404 then it means you are calling a wrong URL. Make sure you have all the variables you have in production on your local.settings.json. You can also try to hardcode localhost:7072 on your proxies to debug – Carlos Alves Jorge
My local.settings.json is up to date and correct for the proxy. I’ve also tried it hard coded with the same result. – LiamGu

2 Answers

6
votes

I've solved this after all.

proxies.json isn't set to copy to the output directory by default.

You need to ensure that it's set to copy always.

In Visual Studio:

Right click proxies.json > click properties > Set Copy to output directory to Copy Always.

In Visual Studio Code (and other editors): Open ProjectName.csproj and add an entry to always copy proxies.json to output directory.

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

This solved the problem with the 404 on my local instance of the function app proxy. In local.settings.json add this to Values:

"AZURE_FUNCTION_PROXY_DISABLE_LOCAL_CALL": true,

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