Files
Spanglish/frontend/src/app/(public)/events/page.tsx
T

30 lines
1010 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { Metadata } from 'next';
import { Event } from '@/lib/api';
import EventsClient from './EventsClient';
const apiUrl = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3001';
// Listing title lives here (not in the layout) so the root title template still
// applies to the sibling /events/[id] detail route. Picks up "%s Spanglish".
export const metadata: Metadata = {
title: 'Upcoming Language Exchange Events in Asunción',
};
// Fetch the public (published) event list on the server so event titles, dates,
// and locations appear in the initial HTML rather than only after JS runs.
async function getEvents(): Promise<Event[]> {
try {
const res = await fetch(`${apiUrl}/api/events`, { next: { revalidate: 60 } });
if (!res.ok) return [];
const data = await res.json();
return data.events || [];
} catch {
return [];
}
}
export default async function EventsPage() {
const events = await getEvents();
return <EventsClient initialEvents={events} />;
}