- Extract revalidateFrontendCache() to backend/src/lib/revalidate.ts - Call revalidation from site-settings when featuredEventId is set/cleared - Ensures homepage shows updated featured event after admin changes Co-authored-by: Cursor <cursoragent@cursor.com>
23 lines
898 B
TypeScript
23 lines
898 B
TypeScript
// Trigger frontend cache revalidation (fire-and-forget)
|
|
// Revalidates both the sitemap and the next-event data (homepage, llms.txt)
|
|
export function revalidateFrontendCache() {
|
|
const frontendUrl = process.env.FRONTEND_URL || 'http://localhost:3002';
|
|
const secret = process.env.REVALIDATE_SECRET;
|
|
if (!secret) {
|
|
console.warn('REVALIDATE_SECRET not set, skipping frontend revalidation');
|
|
return;
|
|
}
|
|
fetch(`${frontendUrl}/api/revalidate`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ secret, tag: ['events-sitemap', 'next-event'] }),
|
|
})
|
|
.then((res) => {
|
|
if (!res.ok) console.error('Frontend revalidation failed:', res.status);
|
|
else console.log('Frontend revalidation triggered (sitemap + next-event)');
|
|
})
|
|
.catch((err) => {
|
|
console.error('Frontend revalidation error:', err.message);
|
|
});
|
|
}
|