Skip to content

Commit

Permalink
fix comment creation
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Apr 29, 2022
1 parent 582272b commit 957a58d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/routes/article/[slug]/comments/index.json.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down

0 comments on commit 957a58d

Please sign in to comment.