Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function proxies break http method routing on HTTP trigger #614

Closed
mdesenfants opened this issue Dec 3, 2017 · 3 comments
Closed

Function proxies break http method routing on HTTP trigger #614

mdesenfants opened this issue Dec 3, 2017 · 3 comments
Assignees

Comments

@mdesenfants
Copy link

Hi folks,

Summary
I'm setting up a Functions app to serve static a static site from blob storage, with the api endpoints hosted in the function app. Some of the functions have the same route, but they are configured to handle different HTTP methods.

When I don't include my proxies.json file in my build, I can route to the correct functions (by HTTP method) without an issue.

Once I include proxies.json in the build build, every "question" request goes to the "PostQuestion" Function, regardless of HTTP method. It looks like it takes the first matching route in alphabetical order, because changing "ReadQuestion" to "AReadQuestion" sends all "question" requests to the GET route instead.

When I stop at a breakpoint in the post route, I can see that the Method property on req is correct ("GET"). If I make post request after changing the name of ReadQuestion to AReadQuestion, I can see that req.Method is correct again ("POST").

Side note: The proxy retrieves static files from the blob storage emulator without an issue.

Code Examples

Function/trigger for GET:

[FunctionName("ReadQuestion")]
public static async Task<HttpResponseMessage> Run(
    [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "question")]HttpRequestMessage req,
    TraceWriter log)
{
    await Task.Delay(0);
    return req.CreateResponse(HttpStatusCode.OK, "Dude.");
}

Function/trigger for POST:

[FunctionName("PostQuestion")]
public static async Task<HttpResponseMessage> Run(
    [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "question")]HttpRequestMessage req,
    [Queue("newq", Connection = "AzureWebJobsStorage")]IAsyncCollector<NewQuestionViewModel> questions,
    TraceWriter log)
{
    NewQuestionViewModel question = null;
    try
    {
        question = await req.Content.ReadAsAsync<NewQuestionViewModel>();
    }
    catch (Exception e)
    {
        log.Error("Could not post new question.", e);
        return req.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not read question. Please try again.");
    }

    await questions.AddAsync(question);

    return req.CreateResponse(HttpStatusCode.Created);
}

Proxies:

{
  "$schema": "http://json.schemastore.org/proxies",
  "proxies": {
    "api": {
      "matchCondition": {
        "route": "/api/{*url}"
      },
      "backendUri": "http://%WEBSITE_HOSTNAME%/api/{url}"
    },
    "default": {
      "matchCondition": {
        "route": "",
        "methods": [ "GET", "HEAD", "OPTIONS" ]
      },
      "backendUri": "%SPA_HOST%/index.html"
    },
    "app": {
      "matchCondition": {
        "route": "{*url}",
        "methods": [ "GET", "HEAD", "OPTIONS" ]
      },
      "backendUri": "%SPA_HOST%/{url}"
    }
  }
}

Environment details

Running in debug mode from VS with Azure Functions CLI 1.0.7 on Windows 10 Pro.

Microsoft Visual Studio Community 2017
Version 15.4.5
VisualStudio.15.Release/15.4.5+27004.2010
Microsoft .NET Framework
Version 4.7.02046

Installed Version: Community

Visual C# 2017 00369-60000-00001-AA565

Azure App Service Tools v3.0.0 15.0.30915.0

Common Azure Tools 1.10

Microsoft Azure Tools 2.9

NuGet Package Manager 4.4.0

Visual Studio Code Debug Adapter Host Package 1.0

WebJobs Tools v1.0.0 15.0.30923.0

@safihamid
Copy link

Yes this is a bug when proxy and function are in the same function app. we will fix this soon. the current workaround is to have your proxies.json and http functions on 2 different function apps.

@mdesenfants
Copy link
Author

Thanks, Hamid! Looking forward to your fix!

@safihamid
Copy link

The fix is released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants