From db6cb7ba8daf8852a59833d932f8083ca3ab940e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=CE=94BL=C3=98=20=E1=84=83=CE=9E?= Date: Wed, 15 May 2024 15:27:34 -0500 Subject: [PATCH] fix: Body is unusable --- src/lib/getBody.ts | 6 +++++- src/lib/startServerAndCreatSvelteHandler.ts | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lib/getBody.ts b/src/lib/getBody.ts index 100a062..9b4826b 100644 --- a/src/lib/getBody.ts +++ b/src/lib/getBody.ts @@ -2,7 +2,11 @@ import type { RequestEvent } from '@sveltejs/kit'; const getBody = async (event: RequestEvent) => { const { request } = event; - return request.headers.get('content-type') === 'application/json' ? request.json() : request.text(); + if (request.body) { + return request.headers.get('content-type') === 'application/json' ? request.json() : request.text(); + } else { + return null; + } }; export { getBody }; diff --git a/src/lib/startServerAndCreatSvelteHandler.ts b/src/lib/startServerAndCreatSvelteHandler.ts index 1bfbb87..a086de7 100644 --- a/src/lib/startServerAndCreatSvelteHandler.ts +++ b/src/lib/startServerAndCreatSvelteHandler.ts @@ -34,7 +34,7 @@ export function startServerAndCreateSvelteKitHandler contextFunction(event), httpGraphQLRequest: { - body: await getBody(event), + body: await getBody(event) ?? '', headers: getHeaders(event), method: request.method, search: new URL(request.url).search || '',