From 957a58d5676f63eb0b3994d51f8256299a6c0c2c Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Fri, 29 Apr 2022 09:54:23 -0700 Subject: [PATCH] fix comment creation --- src/routes/article/[slug]/comments/index.json.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/routes/article/[slug]/comments/index.json.js b/src/routes/article/[slug]/comments/index.json.js index 750723ed..a344e726 100644 --- a/src/routes/article/[slug]/comments/index.json.js +++ b/src/routes/article/[slug]/comments/index.json.js @@ -12,12 +12,13 @@ export async function get({ params, locals }) { }; } -export async function post({ params, body: form, headers, locals }) { +export async function post({ params, request, locals }) { if (!locals.user) { return { status: 401 }; } const { slug } = params; + const form = await request.formData(); const body = form.get('comment'); const { comment } = await api.post( @@ -27,7 +28,7 @@ export async function post({ params, body: form, headers, locals }) { ); // for AJAX requests, return the newly created comment - if (headers.accept === 'application/json') { + if (request.headers.get('accept') === 'application/json') { return { status: 201, // created body: comment