dherault / serverless-offline

Emulate AWS λ and API Gateway locally when developing your Serverless project
MIT License
5.2k stars 794 forks source link

Version 10.1.0 throws internal server error with --disableCookieValidation flag #1576

Closed ahmed-sharief5 closed 2 years ago

ahmed-sharief5 commented 2 years ago

Bug Report

serverless-offline 10.1.0 fails when the --disableCookieValidation flag is used with HTTP API (AWS) with payload 2.0.

Current Behavior

It throws internal server error with the following error

Debug: internal, implementation, error TypeError: Cannot convert undefined or null to object at entries (<anonymous>) at LambdaProxyIntegrationEventV2.create

Sample Code

service: my-service

plugins:
  - serverless-offline

provider:
  runtime: nodejs16.x
  stage: dev
  httpApi:
    payload: "2.0"

functions:
  hello:
    events:
      - httpApi:
          method: get
          path: hello
    handler: handler.hello
'use strict'

const { stringify } = JSON

exports.hello = async function hello() {
  return {
    body: stringify({ foo: 'bar' }),
    statusCode: 200,
  }
}

Expected behavior/code

Its should return a success response

Environment

Expected behavior/code

Handle the below code const cookies = entries(this.#request.state).flatMap(([key, value]) => { if (isArray(value)) { return value.map((v) =>${key}=${v}) } return${key}=${value} })

with this resolves the disable cookie validation

const cookies = this.#request.state ? entries(this.#request.state).flatMap(([key, value]) => { if (isArray(value)) { return value.map((v) =>${key}=${v}) } return${key}=${value} }) : ""

dnalborczyk commented 2 years ago

thank you for filing the the issue @ahmed-sharief5

could you create a PR with your fix?

ahmed-sharief5 commented 2 years ago

@dnalborczyk I had created the pull request #1581

dnalborczyk commented 2 years ago

fixed in: https://github.com/dherault/serverless-offline/pull/1581

released in v10.3.0