javascript - Azure Functions [Node.js] : context. BindingData 不包含我的路由参数(如文档所示)

标签 javascript node.js azure azure-functions

我目前正在构建一个应该检索 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]"
    }
}

提前致谢!

最佳答案

请从 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

上下文.绑定(bind)数据:screenshot of context.bindingData

关于javascript - Azure Functions [Node.js] : context. BindingData 不包含我的路由参数(如文档所示),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68668087/

相关文章:

javascript - 使用 Nodejs 进行网页抓取

node.js - 用于 postgres+node+AWS 弹性 beanstalk 的 package.json

azure - 使用 Azure Active Directory 访问其他服务

JavaScript 上传速度测试有什么想法或帮助吗?

Javascript:获取按键的字符和位置

javascript - 如何在一个地方获得所有 api 响应 (33) 而不会弄得一团糟

c# - 在 Azure 上打开注册页面时出现 "502 - Web server received an invalid response while acting as a gateway or proxy server"错误

javascript - React 组件 - 设置页面标题

javascript - 在 struts2 操作类中从 jquery-ajax 传递的文件值中获取 null

azure - 是否可以在 azcopy 中使用正则表达式?