无服务器离线无法获取路由 [英] Serverless offline not getting route
本文介绍了无服务器离线无法获取路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个刚刚初始化的无服务器项目:
I have a serverless project that I just newly initialized:
severless.yml
:
service: lambda
provider:
name: aws
runtime: nodejs8.10
region: us-east-1
functions:
hello:
handler: handler.hello
events:
- http:
path: /hello
method: GET
plugins:
- serverless-offline
我用 sls offline --port 8080
运行它:
Serverless: Starting Offline: dev/us-east-1
Serverless: Routes for hello:
Serverless: GET /hello
Serverless: Offline listening on http://localhost:8080
并在我的 handler.ts
module.exports.hello = async (event, context) => {
console.log('HIIII')
return {
statusCode: 200,
body: JSON.stringify({
message: 'Go Serverless v1.0! Your function executed successfully!',
input: event,
}),
};
};
我在本地 Postman 上找到了这个端点,但它似乎不起作用.我得到的只是一些 HTML 说 Cannot GET/hello
.我已经尝试向 http://localhost:8080/dev/hello
或 http://localhost:8080/hello
发出 GET 请求,但我仍然遇到相同的错误.我在这里做错了吗?
I hit up this endpoint on Postman locally and it doesn't seem to work. All I get is some HTML saying Cannot GET /hello
. I've tried making GET requests to http://localhost:8080/dev/hello
or http://localhost:8080/hello
and I still get the same errors. Am I doing something wrong here?
推荐答案
我遇到了同样的问题,请确保您没有在该端口上运行其他东西
I had the same issue, make sure you are not running something else on that PORT
这篇关于无服务器离线无法获取路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文