我正在尝试构建 function.json 文件,其中 url 具有我们不知道的自定义结尾。该客户结尾可能包含正斜杠,因此我不能保证这将是一个参数。我当前的代码:
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"route": "{param1}/customer/{param2}/{restOfUrl}",
"name": "req",
"methods": [
"get"
]
},
{
"type": "http",
"direction": "out",
"name": "res"
}
],
"scriptFile": "../dist/src/handlers/myScript.js"
}
例如,当网址为:
时,这可以正常工作...123/customer/456/rest-of-url
但是,如果网址的其余部分包含正斜杠,例如:
...123/customer/456/rest/of/url
我收到 404 未找到。
如果 url 未知并且可能包含正斜杠/,如何正确定义路由?
最佳答案
尝试建议的解决方案后,我发现 this Azure 文档中的 doc。解决方案是 * 剩余参数,它将路径的其余部分作为字符串返回。更改如下所示:
"route": "{param1}/customer/{param2}/{*restOfUrl}"
关于json - Azure Functions 路由与未知 URL 绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72601881/