Serverless offline not getting route

∥☆過路亽.° 提交于 2020-01-04 04:08:09

问题


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

And I run it with 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

and in my 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,
    }),
  };
};

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?


回答1:


You'll need to build your typescript project before serverless-offline can run your code. You can either create a tsconfig.json file and build the project before running serverless offline start, or you can use the serverless-plugin-typescript to do this for you. Just ensure the plugin is declared above the serverless-offline plugin in your serverless.yml file.



来源:https://stackoverflow.com/questions/55130796/serverless-offline-not-getting-route

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!