3

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?

nyphur
  • 2,404
  • 2
  • 24
  • 48
  • Are you sure? I just copy/pasted every part of your example and `http://localhost:8080/hello` works just fine. – noetix Mar 13 '19 at 03:08
  • @Spacebear5000 you mentioned handler.ts, are you sure you are referencing the right js file on the serverless.yml? – dege Mar 13 '19 at 12:00
  • It could be related to your callback. Check whether it is returning something and depending of the tool you use to make the request, it may not recognise the response. – Cleriston Jul 01 '19 at 06:15
  • Most probably you would one need to restart the "serverless offline" command. – Shehan Tis Sep 18 '19 at 06:07

2 Answers2

0

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.

Aaron Stuyvenberg
  • 3,437
  • 1
  • 9
  • 21
0

I had the same issue, make sure you are not running something else on that PORT