【发布时间】: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