Serverless-offline httpApi / post not working / but works on deployed version deployed

Hi

I’m having a very basic (hello-world-style) application where I have a GET/POST on a specific path (see code bellow).
The GET seems to work as expected / the POST is never reaching my code (I think).
I use postman to check the results of the lambda function.
If I deploy the lambda - and execute the same postman-requests on the deployed version - it does work.

I wrote a log message when my code gets called - If I do the test through sls offline - this log message only appears after I do a GET request.
If I start offline (sls offline) and do a POST request in postman - this log-message never appears.

 Operating System:          win32
 Node Version:              15.5.0
 Framework Version:         2.18.0 (local)
 Plugin Version:            4.4.2
 SDK Version:               2.3.2
Components Version:        3.4.6

Code (index.ts)
const serverless = require(‘serverless-http’);

import AWS from ‘aws-sdk’;

import express from ‘express’;

import bodyParser from ‘body-parser’

var dynamodb = require(‘serverless-dynamodb-client’);

const app = express()

app.use(bodyParser.urlencoded({ extended: true }));

app.use(bodyParser.json());

app.use(bodyParser.raw());

console.log(‘setting up express’)

app.get(’/test’, (req, res) => {

console.log(‘in GET’)

res.send(‘Get Hello World!’)

})

app.post(’/test’, (req, res) => {

console.log(‘in POST’)

res.send(‘Post Hello World!’).end()

})

module.exports.handler = serverless(app);

The serverless.yml
service: surveybackend

org: vazg

provider:

name: aws

runtime: nodejs12.x

stage: dev

region: us-east-1

functions:

app:

handler: index.handler

events:

  - httpApi:

      method: '*'

      path: '/{proxy+}'
1 Like

I am also facing this issue. Has anyone been able to figure out what the cause is?

Culprit found! POST request hanging · Issue #1150 · dherault/serverless-offline · GitHub

2 Likes