Files
web2.0-frontend/src/pages/index.tsx
T
einstein 6af5d7fa1f Fix CI build SSG timeouts
- Add backend request timeout to prevent hanging builds

- Make getStaticProps resilient to API failures

- Avoid build-time crawling for dynamic routes (blocking fallback)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-26 18:47:04 +03:00

61 lines
1.5 KiB
TypeScript

import React from "react";
import { NextPage, GetStaticProps } from "next";
import Head from "next/head";
import useSWR from "swr";
import Event from "@models/Event";
import Post from "@models/Feed";
import FrontPageView from "@views/FrontPage/FrontPageView";
import PageWrapper from "@views/common/PageWrapper";
import { fetcher, API, APIPath } from "@api/backend";
const eventApi: API = {
path: APIPath.EVENTS,
queryParams: {
limit: 4,
},
};
const feedApi: API = {
path: APIPath.FEED,
queryParams: {
limit: 4,
},
};
interface InitialProps {
initialEvents: Event[];
initialFeed: Post[];
}
const FrontPage: NextPage<InitialProps> = ({ initialEvents, initialFeed }) => {
const { data: events } = useSWR<Event[]>(eventApi, fetcher, { fallbackData: initialEvents });
const { data: feed } = useSWR<Post[]>(feedApi, fetcher, { fallbackData: initialFeed });
return (
<>
<Head>
<link rel="canonical" href={`${process.env.NEXT_PUBLIC_SITE_URL}/`} />
</Head>
<PageWrapper>
<FrontPageView events={events} feed={feed} />
</PageWrapper>
</>
);
};
export const getStaticProps: GetStaticProps<InitialProps> = async () => {
const [eventsResult, feedResult] = await Promise.allSettled([
fetcher<Event[]>(eventApi),
fetcher<Post[]>(feedApi),
]);
return {
props: {
initialEvents: eventsResult.status === "fulfilled" ? eventsResult.value : [],
initialFeed: feedResult.status === "fulfilled" ? feedResult.value : [],
},
revalidate: 10,
};
};
export default FrontPage;