Prismic webhook send a GET instead of a POST request

Hi,

I'm migrating a website from NextJS pages router to the new app router. I only have one step remaining which is setting up the /revalidate endpoint.

I'm following this documentation and did as follow for my api endpoint.

// src/app/api/revalidate/route.ts

import { revalidateTag } from 'next/cache';
import { NextRequest, NextResponse } from 'next/server';

export async function POST(req: NextRequest) {
  const { secret } = await req.json();

  if (!secret || secret !== process.env.PRISMIC_WEBHOOK_SECRET) {
    return NextResponse.json({ status: 401 });
  }

  revalidateTag('prismic')

  return NextResponse.json({ revalidated: true, now: Date.now() });
}

However, when editing and saving my documents, or triggering the "test-trigger" from the dashboard, the request received by the endpoint is a GET instead of a POST.

AUG 14 20:52:54.47 405 www.pidsinee.com [GET] /api/revalidate

I tried deleting the webhook and creating it again, but I keep receiving GET instead of POST. I also checked on other projects and the "test-trigger" correctly sent a POST request to my endpoint.

To make sure the NextJS endpoint works, I used the following curl command:

curl --request POST \
  --url https://pidsinee.com/api/revalidate \
  --header 'Content-Type: application/json' \
  --data '{
	"secret": "SECRET_REDACTED"
}'

Url to the project is https://pidsinee-www.prismic.io

Cheers,

Well figured it out.

The domain is configured through Vercel DNS, which has a permanent redirect on the root to www.

Meaning when the Prismic webhook sent the POST to https://pidsinee.com it somehow doesn't get forwarded through https://www.pidsinee.com once redirected.

Not sure why, because when I do the curl on https://pidsinee.com it works.

Anyway, just edited the webhook endpoint and added www.

Cheers

3 Likes

Same thing happened to me. Thanks for posting your own solution :+1:

that solves my issue also, thank you for the solution.

1 Like