1

大家好,我已经在 IBM 云上部署了一个函数,我通过 web api 调用它,但是所有函数都可以正常工作,除了那些涉及路由参数的函数,因为我无法提取它们。我正在使用无服务器框架,并且在调用变量时__ow_path它返回空。任何帮助将不胜感激。谢谢。

serverless.yml文件:

getById:
  handler: handler.getById
  overwrite: true
  annotations:
    web-export: true
  events:
    - http: 
        method: GET
        path: /users/{userid}
        resp: http

handler.js文件:

module.exports.getById = async (params) => {
    return {
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({
            params,
            msg: params.__ow_path,
            created: new Date()
        }),
        statusCode: 200
    }
}
4

1 回答 1

1

请将serverless-openwhisk包升级到版本0.18.3。这是由于0.18 中引入的一个已知错误。

上面的例子是有效的。

于 2019-02-27T16:45:53.030 回答