serverless-offline
serverless-offline copied to clipboard
Version 10.1.0 throws internal server error with --disableCookieValidation flag
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} }) : ""
thank you for filing the the issue @ahmed-sharief5
could you create a PR with your fix?
@dnalborczyk I had created the pull request #1581