Azure Functions [Node.js]: context.bindingData不包含我的路由参数的文档建议



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

我特别遵循这一点的说明,但不幸的是,它不会像预期的那样工作。

在我的函数。我有以下一段代码:

{
"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]"
}
}

提前感谢!

请从这里升级到最新的Azure Functions Core Tools,看看您是否仍然看到此行为。

我使用的是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"
}
]
}

使用的URL:/api/MyFunc/FirstValue/OptionalValue

上下文。bindingData: context.bindingData截图

相关内容

最新更新