Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Contentful webhook body parse. #40732

Merged
merged 2 commits into from Sep 22, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/cms-contentful/pages/api/revalidate.js
Expand Up @@ -14,7 +14,7 @@ export default async function handler(req, res) {
}

try {
let postSlug = req.body.fields.slug['en-US']
let postSlug = JSON.parse(req.body).fields.slug['en-US']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the content-type: application/json header not being sent with the Webhook request? If it is present it should already be parsing the req.body to JSON automatically.

x-ref:

if (type === 'application/json' || type === 'application/ld+json') {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't explicitly check headers but I've ran into this before with a webhook so I knew to try this pretty quickly. I can confirm that it goes from doesn't work to works with this change. 😬

I also quickly tried disabling bodyParser through export const config = { ... } to see if something else strange was going on but that also did not work as you'd expect.

I can go back and firm up the headers if needed!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally the content-type header is set from the Webhook although since we don't control it sounds alright to land


// revalidate the individual post and the home page
await res.revalidate(`/posts/${postSlug}`)
Expand Down