From ce987dc837b8b60fe50740f144a34fa5ce567c7b Mon Sep 17 00:00:00 2001 From: Mischa Spiegelmock Date: Tue, 8 Nov 2022 18:13:04 -0800 Subject: [PATCH] fix: Request body was not being passed --- assets/lambda/NextJsHandler.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/assets/lambda/NextJsHandler.ts b/assets/lambda/NextJsHandler.ts index 7f1076c4..06b8bf91 100644 --- a/assets/lambda/NextJsHandler.ts +++ b/assets/lambda/NextJsHandler.ts @@ -3,7 +3,7 @@ // - https://github.com/sladg/nextjs-lambda/blob/master/lib/standalone/server-handler.ts import fs from 'node:fs'; -import { ServerResponse } from 'node:http'; +import { IncomingMessage, ServerResponse } from 'node:http'; import path from 'node:path'; import type { APIGatewayProxyHandlerV2 } from 'aws-lambda'; import type { NextConfig } from 'next'; @@ -42,7 +42,7 @@ const nextHandler = new NextNodeServer(config).getRequestHandler(); // wrap next request handler with serverless-http // to translate from API Gateway v2 to next request/response const server = slsHttp( - async (req, res: ServerResponse) => { + async (req: IncomingMessage, res: ServerResponse) => { await nextHandler(req, res).catch((e) => { console.error(`NextJS request failed due to:`); console.error(e); @@ -52,7 +52,12 @@ const server = slsHttp( }); }, { - binary: false, + binary: ['*/*'], + request: (request: any) => { + // nextjs doesn't parse body if the property exists + // https://github.com/dougmoscrop/serverless-http/issues/227 + delete request.body; + }, provider: 'aws', } );