如何解决无服务器离线:“路径”参数必须是字符串类型收到未定义
不知道为什么会发生这种情况,但我有一个非常简单的无服务器应用程序可以正常工作,但是现在当我运行 sls offline start
时出现上述错误。我找到了罪魁祸首,它是函数内部的 events
。
这是 serverless.yml
文件:
service: hello-world-offline
provider:
name: aws
runtime: nodejs12.x
region: eu-east-1
stage: dev
plugins:
- serverless-offline
functions:
hello-world:
handler: handler.handle # required,handler set in AWS Lambda
events:
- http:
path: hello-world
method: get
cors: true
这是 handler.js
文件:
module.exports.handle = async (event,ctx,cb) => {
cb(null,{
statusCode: 200,body: JSON.stringify({ message: "hello world" })
})
}
如果我去掉函数 events
中的 hello-world
,一切都可以与 sls offline start
一起正常工作,当然我实际上无法在本地击中端点。我尝试通过添加引号使其成为硬字符串,但没有任何作用。
编辑:结果是使用 yarn workspaces
时会发生这种情况。如果我将它放在 packages/my-serverless-app
结构中,然后 cd 进入文件夹以运行 sls offline start
命令,就会发生这种情况。如果我将它从结构中移除,它就可以正常工作。
解决方法
改变
events:
- http:
path: hello-world
method: get
cors: true
到
events:
- httpApi:
path: hello-world
method: get
这应该可行!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。