From 8f67de07d86399c20356ebe62945fe17d9d791a7 Mon Sep 17 00:00:00 2001 From: "Zane J. Chua" Date: Mon, 14 Aug 2023 03:13:48 +0000 Subject: [PATCH] feat: use comment-worker instead of staticman --- src/components/CommentForm.jsx | 20 +++++++++++--------- staticman.yml | 6 +----- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/components/CommentForm.jsx b/src/components/CommentForm.jsx index 60738f59..1f1b84d8 100644 --- a/src/components/CommentForm.jsx +++ b/src/components/CommentForm.jsx @@ -19,23 +19,25 @@ const CommentForm = ({ slug, className }) => { const handleSubmission = async () => { setIsLoading(true); setConfirmationMessage(''); - const formData = new URLSearchParams(); - formData.append('fields[slug]', slug); - formData.append('fields[name]', name); - formData.append('fields[email]', email); - formData.append('fields[message]', message); if (name === '' || email === '' || message === '') { setIsLoading(false); setConfirmationMessage('Uh oh. Did you miss something?'); } else { - fetch('https://staticman.zanechua.com/v2/entry/zanechua/website/master/comments', { + fetch('https://comments.zanechua.com/api/handle/form', { method: 'POST', - data: formData, - headers: { 'Content-Type': 'application/x-www-form-urlencoded' } + body: JSON.stringify({ + fields: { + slug, + name, + email, + message + } + }), + headers: { 'Content-Type': 'application/json' } }) .then(response => { - if (response.status === 200) { + if (response.status === 200 || response.status === 201) { resetInputData(); setConfirmationMessage( 'Thanks! Your comment will be published after it has been reviewed.' diff --git a/staticman.yml b/staticman.yml index 00acb7d5..8e6d1f1f 100644 --- a/staticman.yml +++ b/staticman.yml @@ -9,10 +9,6 @@ comments: # not here is part of the request, an error will be thrown. allowedFields: ['name', 'email', 'url', 'message', 'slug'] - # When allowedOrigins is defined, only requests sent from one of the domains - # listed will be accepted. - allowedOrigins: ["zanechua.com"] - auth: required: false @@ -81,4 +77,4 @@ comments: # List of transformations to apply to any of the fields supplied. Keys are # the name of the field and values are possible transformation types. transforms: - email: md5 \ No newline at end of file + email: sha512