azure-functions-host: Proxies with wildcards don't work with parameters

Given a proxies.json file like this:

{
  "$schema": "http://json.schemastore.org/proxies",
  "proxies": {
    "api": {
      "matchCondition": {
        "route": "/api/{*restOfPath}"
      },
      "backendUri": "https://localhost/api/{restOfPath}"
    }
  }
}

Calling a function with an http trigger and a route with a parameter, such as “test/{id}”, with a url like “test/123” results in an error:

System.Private.CoreLib: Exception while executing function: Test. Microsoft.Azure.WebJobs.Host: Exception binding parameter 'id'. Microsoft.Azure.WebJobs.Host: Binding data does not contain expected value 'id'.

This works with a v1 function app. Does not work with v2 function app (either 2.0.12115.0 or 2.0.12134.0).

Workaround is to create a proxy for each endpoint that has a binding parameter.

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Comments: 29 (5 by maintainers)

Most upvoted comments

Some workaround in the meantime:

private static async Task<RouteValueDictionary> GetRouteValuesAsync(HttpRequest req, ExecutionContext context)
{
    var routingFeature = req.HttpContext.Features.Get<IRoutingFeature>();
    var webJobsRouter = routingFeature.RouteData.Routers.Single(r => r is WebJobsRouter) as WebJobsRouter;
    var functionRouteTemplate = webJobsRouter.GetFunctionRouteTemplate(context.FunctionName);

    var functionRoute = new Route(webJobsRouter, functionRouteTemplate, webJobsRouter.ConstraintResolver);
    var newRouteContext = new RouteContext(req.HttpContext);
    await functionRoute.RouteAsync(newRouteContext);
    return newRouteContext.RouteData.Values;
}

[FunctionName("UsersHttpTrigger")]
public static async Task<IActionResult> Run(
    [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "users/{id}")] HttpRequest req,
    ILogger log,
    ExecutionContext context)
{
    var routeValues = await GetRouteValuesAsync(req, context);
    var idValue = routeValues["id"];
    ...
}