18 lines
534 B
TypeScript
18 lines
534 B
TypeScript
import type { PageServerLoad } from './$types';
|
|
import type { TournamentInfo } from '$lib/types';
|
|
|
|
export const load: PageServerLoad = async ({ fetch }) => {
|
|
try {
|
|
const response = await fetch('/api/tournament');
|
|
if (!response.ok) {
|
|
return { tournaments: [] as TournamentInfo[] };
|
|
}
|
|
const data = await response.json();
|
|
return {
|
|
tournaments: (data?.tournaments ?? []) as TournamentInfo[]
|
|
};
|
|
} catch (err) {
|
|
console.error('Failed to load tournaments', err);
|
|
return { tournaments: [] as TournamentInfo[] };
|
|
}
|
|
};
|