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() diff --git a/src/next-edge/index.ts b/src/next-edge/index.ts index 052a974..3c9bed9 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", })