Skip to content

FlashcardNot attempted

On-demand revalidation webhook

Recall it before you reveal

Your CMS must refresh cached product pages when an editor publishes. Sketch the endpoint.

Space to reveal
Show answer & explanation

A Route Handler the CMS calls, protected by a shared secret:

// app/api/revalidate/route.ts
import { revalidateTag } from 'next/cache';
export async function POST(req: Request) {
const { tag, secret } = await req.json();
if (secret !== process.env.REVALIDATION_SECRET) return Response.json({ error: 'Invalid secret' }, { status: 401 });
if (!tag) return Response.json({ error: 'tag is required' }, { status: 400 });
revalidateTag(tag);
return Response.json({ revalidated: true });
}

Prefer sending the secret in a header, and compare it in constant time. Use granular tags (product-123).