Skip to content

Commit

Permalink
Merge pull request #15 from jetbridge/fix-req-body
Browse files Browse the repository at this point in the history
fix: Request body was not being passed to NextJS
  • Loading branch information
revmischa authored Nov 9, 2022
2 parents a9802b2 + ce987dc commit b8af1be
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions assets/lambda/NextJsHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand All @@ -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',
}
);
Expand Down

0 comments on commit b8af1be

Please sign in to comment.