diff --git a/src/templates/schedule.tsx b/src/templates/schedule.tsx index 17b8246413..34b67516c5 100644 --- a/src/templates/schedule.tsx +++ b/src/templates/schedule.tsx @@ -8,9 +8,47 @@ import ScheduleList, { ScheduleSession, } from "../components/Conf/Schedule/ScheduleList" -const ScheduleTemplate: FC> = ({ - pageContext: { schedule }, -}) => { +const fetchData = async (url: string) => { + try { + const response = await fetch(url, { + method: "POST", + headers: { + "Content-Type": "application/json", + "User-Agent": "GraphQL Conf / GraphQL Foundation", + }, + }) + const data = await response.json() + return data + } catch (error: any) { + throw new Error( + `Error fetching data from ${url}: ${error.message || error.toString()}` + ) + } +} + +export async function getServerData() { + try { + const schedule: ScheduleSession[] = await fetchData( + `https://graphqlconf23.sched.com/api/session/list?api_key=${process.env.SCHED_ACCESS_TOKEN}&format=json` + ) + + return { + props: { + schedule, + }, + } + } catch (error) { + return { + status: 500, + headers: {}, + props: {}, + } + } +} + +const ScheduleTemplate: FC< + PageProps<{}, {}, {}, { schedule: ScheduleSession[] }> +> = ({ serverData: { schedule } }) => { return (