【问题标题】:Azure Functions [Node.js]: context.bindingData not containing my route params as documentation suggestsAzure Functions [Node.js]:context.bindingData 不包含我的路由参数,如文档所示
【发布时间】:2021-09-01 22:16:34
【问题描述】:

我目前正在构建一个应该检索 2 个路由参数的函数(第一个是必需的,第二个是可选的),但是尽管遵循了他们的文档,但我还是遇到了一些问题。

具体来说,我正在遵循this 的一些说明,但不幸的是它不会按预期工作。

在我的 function.json 中,我有以下代码:

{
  "bindings": [
    {
      "authLevel": "anonymous",
      "type": "httpTrigger",
      "name": "req",
      "direction": "in",
      "methods": [ "get" ],
      "route": "MyFunction/{courseId:alpha}/{locale:alpha?}"
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    }
  ]
}

说明告诉我可以访问context.bindingData 上的这两个参数,但它没有出现。我(此时)可以访问信息的唯一方法是拆分路径(位于context.bindingData.path 上)。 不过我真的不喜欢这种解决方案,尤其是当文档告诉另一种方法时。

这里有什么context.bindingData

{
    "invocationId": "1067e7e5-f85f-481c-8605-645cf78dcb25",
    "path": "MyFunction/windscreen/en",
    "query": {
        
    },
    "headers": {
        "cache-Control": "max-age=0",
        "connection": "keep-alive",
        "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
        "accept-Encoding": "gzip,deflate,br",
        "accept-Language": "da-DK,da;q=0.9,en-US;q=0.8,en;q=0.7,la;q=0.6,nb;q=0.5",
        "host": "localhost",
        "user-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36",
        "upgrade-Insecure-Requests": "1",
        "content-Length": "0",
        "sec-ch-ua": "\"Chromium\";v=\"92\", \" Not A;Brand\";v=\"99\", \"Google Chrome\";v=\"92\"",
        "sec-ch-ua-mobile": "?0",
        "sec-Fetch-Site": "none",
        "sec-Fetch-Mode": "navigate",
        "sec-Fetch-User": "?1",
        "sec-Fetch-Dest": "document",
        "x-Forwarded-For": "127.0.0.1"
    },
    "sys": {
        "methodName": "MyFunction",
        "utcNow": "2021-08-05T13:56:43.800Z",
        "randGuid": "[Censored]"
    }
}

提前致谢!

【问题讨论】:

    标签: javascript node.js azure azure-functions


    【解决方案1】:

    请从 here 升级到最新的 Azure Functions 核心工具,看看你是否仍然看到这种行为。

    我使用的是 3.0.3477 版本,无法重现。供参考,使用的投标信息和你的差不多,如下图:

     {
      "bindings": [
        {
          "authLevel": "anonymous",
          "type": "httpTrigger",
          "direction": "in",
          "name": "req",
          "methods": [ "get" ],
          "route": "MyFunc/{firstParam:alpha}/{optionalParam:alpha?}"
        },
        {
          "type": "http",
          "direction": "out",
          "name": "res"
        }
      ]
    }
    

    使用的网址:/api/MyFunc/FirstValue/OptionalValue

    context.bindingData:screenshot of context.bindingData

    【讨论】:

      猜你喜欢
      • 2022-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多