Azure-functions-core-tools: proxies does not work when backendUri is another port on same machine

Created on 16 Nov 2017  路  13Comments  路  Source: Azure/azure-functions-core-tools

If you setup a proxies.json to point to another service running on localhost, it seems to only try and proxy to the same function app. From the outside it feels liek the proxy runtime isn't taking port into account when deciding if it's proxying to another path on the same service.

Example: if I'm running the functions cli on port 7071 and a client app on 8080. Navigating to localhost:7071/app/ will actually give back the "Your Azure Function App is up and running." placeholder page instead of the content from the other service. If I change the proxy to anything not on localhost, it will go fetch that content properly.

{
  "$schema": "http://json.schemastore.org/proxies",
  "proxies": {
    "proxy-app": {
      "matchCondition": {
        "route": "/app/{*restOfPath}",
        "methods": [
          "GET"
        ]
      },
      "backendUri": "http://localhost:8080/{restOfPath}"
    }
  }
}

Using CLI 1.0.7

Most helpful comment

@alexkarcher-msft would you please add this to the docs?
"AZURE_FUNCTION_PROXY_DISABLE_LOCAL_CALL": "true"
also add this one: AZURE_FUNCTION_PROXY_BACKEND_URL_DECODE_SLASHES : true as referenced in https://github.com/Azure/azure-functions-host/issues/2249

All 13 comments

Are there any workarounds for this?

@johlrich . I am running the container @ http://192.168.99.100 - but for me the proxy isnt working even if I give an external URL. Are there any additional settings needed?

With the below proxies.json
On Azure: yyyyyy.azurewebsites.net/vGoogle --> Directs to www.google.com
On Local: http://192.168.99.100:8080/vGoogle --> 404 error
Note that http://192.168.99.100:8080 works fine, and shows up the default function app page

I also saw, there is an open issue @ https://github.com/Azure/app-service-announcements/issues/68 - is this something related? If so, which versions did you use when you ran the localhost:7071?

proxies.json
{
"$schema": "http://json.schemastore.org/proxies",
"proxies": {
"AllTraffic": {
"matchCondition": {
"route": "{*}",
"methods": [
"GET"
]
},
"backendUri": "http://www.google.com"
}
}
}

@veeshall you need to give the route parameter a name {*} is invalid. Your proxies.json should work fine if you change it to {*everything} (or any other name)

@johlrich - sorry, might have been a copy paste error. I actually have below. But it still doesn't work on the local. Not sure if it has anything to do with not being "localhost", but an IP(?)

"route": "vGoogle",

Are you using the latest 2.0 jessie image as well? (microsoft/azure-functions-runtime:2.0.0-jessie)

@johlrich I have the same issue. I have an angular-cli dev server running at localhost:4200 and I can't seem to proxy anything from the functions to that. However, if I use a URL that isn't localhost, it works just fine.

To test this, I added an alias in the Windows' hosts file 127.0.0.1 and using that as the URL in my proxies.json file to proxy to my other localhost dev server. This works for me so I am going to use this as a workaround until this issue is looked into and fixed.

EDIT: Slightly out of scope for Azure Functions but if you are going to try my workaround, you will have to disable the host verification in Angular CLI for it to work. Do that at your own risk. I am running the dev server on my local machine so I am ok with it and disabled it by passing the flag --disableHostCheck true to the angular-cli.

I am not able to get even a simple proxy to work. Is there a console message if the proxy is found?

CLI - 2.0.1-beta1.15

{
  "proxies": {
    "all": {
      "matchCondition": {
        "route": "test"
      },
      "responseOverrides": {
        "response.body": "Test",
        "response.headers.Content-Type": "text/plain"
      }
    }
  }
}

In 2.0.1-beta.22 there is no proxy support. Any update when it will be available?

I'm also getting the issue: when running on localhost not being able to proxy to another port on localhost where my webapp is running.

Yes the lack of proxy support for version 2 is kind of a showstopper.

Hi guys, See #488 for proxy in v2

Yes this is a separate issue. in order for this to work locally. you will need to disable proxy routing locally to the function app.
Add this app setting and everything will work:
"AZURE_FUNCTION_PROXY_DISABLE_LOCAL_CALL": "true"

One way to add is to update your local.settings.json file.

@safihamid thanks - that got me up and running. It would be very useful for this to be mentioned in the official proxies documentation, as it took me a long time to track down why it wasn't working.

@alexkarcher-msft would you please add this to the docs?
"AZURE_FUNCTION_PROXY_DISABLE_LOCAL_CALL": "true"
also add this one: AZURE_FUNCTION_PROXY_BACKEND_URL_DECODE_SLASHES : true as referenced in https://github.com/Azure/azure-functions-host/issues/2249

Was this page helpful?
0 / 5 - 0 ratings