- SSR next event on homepage; pass initialEvent from server to avoid client-only content - Add schema.org Event JSON-LD on homepage when next event exists - Dynamic homepage metadata (description, OG, Twitter) with next event date - Add dynamic /llms.txt route for AI-friendly plain-text event info - Revalidation: support next-event tag; backend revalidates sitemap + next-event on event CUD - Allow /llms.txt in robots.txt Co-authored-by: Cursor <cursoragent@cursor.com>
32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import { revalidateTag } from 'next/cache';
|
|
import { NextRequest, NextResponse } from 'next/server';
|
|
|
|
export async function POST(request: NextRequest) {
|
|
try {
|
|
const body = await request.json();
|
|
const { secret, tag } = body;
|
|
|
|
// Validate the revalidation secret
|
|
const revalidateSecret = process.env.REVALIDATE_SECRET;
|
|
if (!revalidateSecret || secret !== revalidateSecret) {
|
|
return NextResponse.json({ error: 'Invalid secret' }, { status: 401 });
|
|
}
|
|
|
|
// Validate tag(s) - supports single tag or array of tags
|
|
const allowedTags = ['events-sitemap', 'next-event'];
|
|
const tags: string[] = Array.isArray(tag) ? tag : [tag];
|
|
const invalidTags = tags.filter((t: string) => !allowedTags.includes(t));
|
|
if (tags.length === 0 || invalidTags.length > 0) {
|
|
return NextResponse.json({ error: 'Invalid tag' }, { status: 400 });
|
|
}
|
|
|
|
for (const t of tags) {
|
|
revalidateTag(t);
|
|
}
|
|
|
|
return NextResponse.json({ revalidated: true, tags, now: Date.now() });
|
|
} catch {
|
|
return NextResponse.json({ error: 'Failed to revalidate' }, { status: 500 });
|
|
}
|
|
}
|