These short links always resolve to the latest upcoming or featured event so they can be shared without updating when events rotate. Co-authored-by: Cursor <cursoragent@cursor.com>
24 lines
730 B
TypeScript
24 lines
730 B
TypeScript
import { redirect } from 'next/navigation';
|
|
|
|
const apiUrl = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3001';
|
|
|
|
async function getNextEventSlug(): Promise<string | null> {
|
|
try {
|
|
const revalidateSeconds =
|
|
parseInt(process.env.NEXT_EVENT_REVALIDATE_SECONDS || '3600', 10) || 3600;
|
|
const response = await fetch(`${apiUrl}/api/events/next`, {
|
|
next: { tags: ['next-event'], revalidate: revalidateSeconds },
|
|
});
|
|
if (!response.ok) return null;
|
|
const data = await response.json();
|
|
return data.event?.slug || null;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export default async function NextEventPage() {
|
|
const slug = await getNextEventSlug();
|
|
redirect(slug ? `/events/${slug}` : '/events');
|
|
}
|