From 1f78a57ef94dd10d38cc0f75795d271299f6d3bc Mon Sep 17 00:00:00 2001 From: timbastin Date: Thu, 28 Nov 2024 16:59:45 +0100 Subject: [PATCH 1/3] adds readRawBody function to make it work with disabled body parser --- src/next-edge/index.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/next-edge/index.ts b/src/next-edge/index.ts index 052a974..b591400 100644 --- a/src/next-edge/index.ts +++ b/src/next-edge/index.ts @@ -1,4 +1,3 @@ -import { Buffer } from "buffer" import { SerializeOptions as CookieSerializeOptions, serialize } from "cookie" import { IncomingHttpHeaders } from "http" import { isText } from "istextorbinary" @@ -10,6 +9,15 @@ import { defaultForwardedHeaders } from "../common/default-forwarded-headers" import { processLocationHeader } from "../common/process-location-header" import { guessCookieDomain } from "../common/get-cookie-domain" +function readRawBody(req: NextApiRequest): Promise { + return new Promise((resolve, reject) => { + const chunks: Uint8Array[] = []; + req.on('data', (chunk) => chunks.push(chunk)); + req.on('end', () => resolve(Buffer.concat(chunks))); + req.on('error', (err) => reject(err)); + }) +} + export function filterRequestHeaders( headers: IncomingHttpHeaders, forwardAdditionalHeaders?: string[], @@ -112,7 +120,7 @@ export function createApiHandler(options: CreateApiHandlerOptions) { headers, body: req.method !== "GET" && req.method !== "HEAD" - ? JSON.stringify(req.body) + ? await readRawBody(req) : null, redirect: "manual", }) From b6d12c9ed3749cceb54433bbecdaf1122f81572b Mon Sep 17 00:00:00 2001 From: timbastin Date: Thu, 28 Nov 2024 18:20:06 +0100 Subject: [PATCH 2/3] code formatting --- src/next-edge/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/next-edge/index.ts b/src/next-edge/index.ts index b591400..3c9bed9 100644 --- a/src/next-edge/index.ts +++ b/src/next-edge/index.ts @@ -11,10 +11,10 @@ import { guessCookieDomain } from "../common/get-cookie-domain" function readRawBody(req: NextApiRequest): Promise { return new Promise((resolve, reject) => { - const chunks: Uint8Array[] = []; - req.on('data', (chunk) => chunks.push(chunk)); - req.on('end', () => resolve(Buffer.concat(chunks))); - req.on('error', (err) => reject(err)); + const chunks: Uint8Array[] = [] + req.on("data", (chunk) => chunks.push(chunk)) + req.on("end", () => resolve(Buffer.concat(chunks))) + req.on("error", (err) => reject(err)) }) } From 37258c7e6a299f5ba6960fbd983d2b79f9994bac Mon Sep 17 00:00:00 2001 From: aeneasr <3372410+aeneasr@users.noreply.github.com> Date: Thu, 2 Jan 2025 11:56:23 +0100 Subject: [PATCH 3/3] chore: synchronize workspaces --- src/next-edge/index.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/next-edge/index.test.ts b/src/next-edge/index.test.ts index 2448823..6bcf688 100644 --- a/src/next-edge/index.test.ts +++ b/src/next-edge/index.test.ts @@ -17,7 +17,7 @@ function createApp(options: CreateApiHandlerOptions): AppResult { const handler = createApiHandler({ apiBaseUrlOverride: - "https://youthful-feynman-ml50dfb20g.projects.staging.oryapis.dev", + "https://youthful-feynman-ml50dfb20g.projects.staging.oryapis.dev", ...options, }) const router = express.Router()