NextJS Revalidate API
import { NextRequest, NextResponse } from 'next/server';
import { revalidateTag } from 'next/cache';
export async function POST(request: NextRequest) {
const {secret} = await request.json();
if (secret !== process.env.SECRET_TOKEN) {
return NextResponse.json({message: 'Invalid Token'}, {status: 401})
}
console.log('revalidating posts...');
revalidateTag('posts');
return NextResponse.json({ revalidated: true, now: Date.now() });
}