Skip to content

Commit

Permalink
fix: Body is unusable
Browse files Browse the repository at this point in the history
  • Loading branch information
pabl-o-ce committed May 15, 2024
1 parent 377d86d commit db6cb7b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/lib/getBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
2 changes: 1 addition & 1 deletion src/lib/startServerAndCreatSvelteHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function startServerAndCreateSvelteKitHandler<Context extends BaseContext
const httpGraphQLResponse = await server.executeHTTPGraphQLRequest({
context: () => contextFunction(event),
httpGraphQLRequest: {
body: await getBody(event),
body: await getBody(event) ?? '',
headers: getHeaders(event),
method: request.method,
search: new URL(request.url).search || '',
Expand Down

0 comments on commit db6cb7b

Please sign in to comment.