serverless-offline icon indicating copy to clipboard operation
serverless-offline copied to clipboard

Version 10.1.0 throws internal server error with --disableCookieValidation flag

Open ahmed-sharief5 opened this issue 2 years ago • 2 comments

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

  • file: serverless.yml
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
  • file: handler.js
'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

  • serverless
  • Framework Core: 3.22.0 (local) 3.22.0 (global)
  • Plugin: 6.2.2
  • SDK: 4.3.2
  • serverless-offline version: 10.1.0
  • node.js version: 16.17.0
  • OS: macOS 12.4

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} }) : ""

ahmed-sharief5 avatar Sep 19 '22 17:09 ahmed-sharief5

thank you for filing the the issue @ahmed-sharief5

could you create a PR with your fix?

dnalborczyk avatar Sep 22 '22 00:09 dnalborczyk

@dnalborczyk I had created the pull request #1581

ahmed-sharief5 avatar Sep 22 '22 13:09 ahmed-sharief5

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

released in v10.3.0

dnalborczyk avatar Sep 25 '22 23:09 dnalborczyk