最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

无服务器脱机的可选路径参数

运维笔记admin7浏览0评论

无服务器脱机的可选路径参数

无服务器脱机的可选路径参数

我试图建立与可选参数的GET请求,但我得到一个错误,当我在本地调用的URL没有可选参数。它工作正常,在线上拉姆达虽然。我做错了什么?

我使用的是无服务器版本1.24.1与无服务器脱机插件3.16.0版本

这里是我的serverless.yml请求定义:

functions:
getitems:
    handler: lambda.handler
    events:
      - http:
            path: item/store/{storeid}/{itemstatus}
            method: get
            cors: true
            request:
                parameters:
                  paths:
                    storeid: true
                    itemstatus: false

这个网址的工作原理:

http://localhost:3000/item/store/123456/used

这不

http://localhost:3000/item/store/123456

并给我这个输出

{
   statusCode: 404,
   error: "Serverless-offline: route not found.",
   currentRoute: "get - /item/store/123456",
   existingRoutes: [
       "get - item/store/{storeid}/{itemstatus}"
   ]
}

非常感谢

回答如下:

添加“?”在PARAMS后可以使它发挥作用。

functions:
  getitems:
  handler: lambda.handler
  events:
    - http:
        path: item/store/{storeid}/{itemstatus?}
        method: get
        cors: true
发布评论

评论列表(0)

  1. 暂无评论