Skip to content

Commit db6cb7b

Browse files
committed
fix: Body is unusable
1 parent 377d86d commit db6cb7b

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/lib/getBody.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import type { RequestEvent } from '@sveltejs/kit';
22

33
const getBody = async (event: RequestEvent) => {
44
const { request } = event;
5-
return request.headers.get('content-type') === 'application/json' ? request.json() : request.text();
5+
if (request.body) {
6+
return request.headers.get('content-type') === 'application/json' ? request.json() : request.text();
7+
} else {
8+
return null;
9+
}
610
};
711

812
export { getBody };

src/lib/startServerAndCreatSvelteHandler.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function startServerAndCreateSvelteKitHandler<Context extends BaseContext
3434
const httpGraphQLResponse = await server.executeHTTPGraphQLRequest({
3535
context: () => contextFunction(event),
3636
httpGraphQLRequest: {
37-
body: await getBody(event),
37+
body: await getBody(event) ?? '',
3838
headers: getHeaders(event),
3939
method: request.method,
4040
search: new URL(request.url).search || '',

0 commit comments

Comments
 (0)