From 6af5d7fa1fcd5641ea0651891b28114e7538cc6c Mon Sep 17 00:00:00 2001 From: einstein Date: Tue, 26 May 2026 18:47:04 +0300 Subject: [PATCH] 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> --- src/api/backend.ts | 3 ++ src/pages/events/[id].tsx | 55 +++++++++++++++++------------------ src/pages/feed/[id].tsx | 54 ++++++++++++++++------------------ src/pages/in_english.tsx | 11 ++++--- src/pages/index.tsx | 11 ++++--- src/pages/kilta/toiminta.tsx | 13 +++++---- src/pages/signup/[id].tsx | 52 ++++++++++++++++----------------- src/pages/yritysyhteistyo.tsx | 7 +++-- 8 files changed, 105 insertions(+), 101 deletions(-) diff --git a/src/api/backend.ts b/src/api/backend.ts index d6700f0..87a82d9 100644 --- a/src/api/backend.ts +++ b/src/api/backend.ts @@ -1,8 +1,11 @@ import axios, { AxiosInstance, AxiosRequestConfig } from "axios"; import { getAccessTokenCookie } from "@utils/auth"; +const API_TIMEOUT_MS = 10000; + const axiosInstance: AxiosInstance = axios.create({ baseURL: process.env.NEXT_PUBLIC_API_URL, + timeout: API_TIMEOUT_MS, }); export enum APIPath { diff --git a/src/pages/events/[id].tsx b/src/pages/events/[id].tsx index 408a4bb..6567fc8 100644 --- a/src/pages/events/[id].tsx +++ b/src/pages/events/[id].tsx @@ -14,14 +14,13 @@ interface InitialProps { const EventPage: NextPage = ({ event }) => { const router = useRouter(); - const { id } = router.query; if (router.isFallback) return ; return ( <> - + @@ -30,36 +29,34 @@ const EventPage: NextPage = ({ event }) => { ); }; -export const getStaticPaths: GetStaticPaths = async () => { - const allEvents = await EventApi.getEvents(); - const paths = allEvents.map((e: Event) => ({ - params: { - id: String(e.id), - }, - } - )); - return { - paths, - fallback: true, - }; -}; +export const getStaticPaths: GetStaticPaths = async () => ({ + paths: [], + fallback: "blocking", +}); export const getStaticProps: GetStaticProps = async ({ params }) => { - const { id } = params; - let notFound = false; - let event: Event; - try { - event = await EventApi.getEvent(Number(id)); - } catch (err) { - notFound = true; + const id = Number(params?.id); + if (!id) { + return { + notFound: true, + revalidate: 10, + }; + } + + try { + const event = await EventApi.getEvent(id); + return { + props: { + event, + }, + revalidate: 10, // Required for deleting hidden pages + }; + } catch { + return { + notFound: true, + revalidate: 10, + }; } - return { - props: { - event, - }, - revalidate: 10, // Required for deleting hidden pages - notFound, - }; }; export default EventPage; diff --git a/src/pages/feed/[id].tsx b/src/pages/feed/[id].tsx index b791266..8bf9993 100644 --- a/src/pages/feed/[id].tsx +++ b/src/pages/feed/[id].tsx @@ -14,14 +14,13 @@ interface InitialProps { const FeedPage: NextPage = ({ post }) => { const router = useRouter(); - const { id } = router.query; if (router.isFallback) return ; return ( <> - + @@ -30,37 +29,34 @@ const FeedPage: NextPage = ({ post }) => { ); }; -export const getStaticPaths: GetStaticPaths = async () => { - const feed = await FeedApi.getFeed(); - const paths = feed.map((post: Post) => ({ - params: { - id: String(post.id), - }, - } - )); - return { - paths, - fallback: true, - }; -}; +export const getStaticPaths: GetStaticPaths = async () => ({ + paths: [], + fallback: "blocking", +}); export const getStaticProps: GetStaticProps = async ({ params }) => { - const { id } = params; - let notFound = false; - let post: Post; - try { - post = await FeedApi.getPost(Number(id)); - } catch (err) { - notFound = true; + const id = Number(params?.id); + if (!id) { + return { + notFound: true, + revalidate: 10, + }; } - return { - props: { - post, - }, - revalidate: 10, // Required for deleting hidden pages - notFound, - }; + try { + const post = await FeedApi.getPost(id); + return { + props: { + post, + }, + revalidate: 10, // Required for deleting hidden pages + }; + } catch { + return { + notFound: true, + revalidate: 10, + }; + } }; export default FeedPage; diff --git a/src/pages/in_english.tsx b/src/pages/in_english.tsx index 393f8fd..78db8f1 100644 --- a/src/pages/in_english.tsx +++ b/src/pages/in_english.tsx @@ -44,12 +44,15 @@ const InEnglishPage: NextPage = ({ initialEvents, initialFeed }) = }; export const getStaticProps: GetStaticProps = async () => { - const initialEvents = await fetcher(eventApi); - const initialFeed = await fetcher(feedApi); + const [eventsResult, feedResult] = await Promise.allSettled([ + fetcher(eventApi), + fetcher(feedApi), + ]); + return { props: { - initialEvents, - initialFeed, + initialEvents: eventsResult.status === "fulfilled" ? eventsResult.value : [], + initialFeed: feedResult.status === "fulfilled" ? feedResult.value : [], }, revalidate: 10, }; diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 5b93a16..b3ccefd 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -43,12 +43,15 @@ const FrontPage: NextPage = ({ initialEvents, initialFeed }) => { }; export const getStaticProps: GetStaticProps = async () => { - const initialEvents = fetcher(eventApi); - const initialFeed = fetcher(feedApi); + const [eventsResult, feedResult] = await Promise.allSettled([ + fetcher(eventApi), + fetcher(feedApi), + ]); + return { props: { - initialEvents: await initialEvents, - initialFeed: await initialFeed, + initialEvents: eventsResult.status === "fulfilled" ? eventsResult.value : [], + initialFeed: feedResult.status === "fulfilled" ? feedResult.value : [], }, revalidate: 10, }; diff --git a/src/pages/kilta/toiminta.tsx b/src/pages/kilta/toiminta.tsx index b4d4577..73d42c9 100644 --- a/src/pages/kilta/toiminta.tsx +++ b/src/pages/kilta/toiminta.tsx @@ -3,9 +3,7 @@ import { NextPage, GetStaticProps } from "next"; import Head from "next/head"; import useSWR from "swr"; import Event from "@models/Event"; -import EventApi from "@api/eventApi"; import Post from "@models/Feed"; -import FeedApi from "@api/feedApi"; import ActualPageView from "@views/ActualPage/ActualPageView"; import PageWrapper from "@views/common/PageWrapper"; import { fetcher, APIPath, API } from "@api/backend"; @@ -40,12 +38,15 @@ const ActualPage: NextPage = ({ initialEvents, initialFeed }) => { }; export const getStaticProps: GetStaticProps = async () => { - const initialEvents = await EventApi.getEvents(); - const initialFeed = await FeedApi.getFeed(); + const [eventsResult, feedResult] = await Promise.allSettled([ + fetcher(eventApi), + fetcher(feedApi), + ]); + return { props: { - initialEvents, - initialFeed, + initialEvents: eventsResult.status === "fulfilled" ? eventsResult.value : [], + initialFeed: feedResult.status === "fulfilled" ? feedResult.value : [], }, revalidate: 10, }; diff --git a/src/pages/signup/[id].tsx b/src/pages/signup/[id].tsx index 9c759f6..6d43741 100644 --- a/src/pages/signup/[id].tsx +++ b/src/pages/signup/[id].tsx @@ -112,36 +112,34 @@ const SignUpPage: NextPage = ({ initialForm }) => { ); }; -export const getStaticPaths: GetStaticPaths = async () => { - const allForms = await SignupApi.getForms(); - const paths = allForms.map((e: SignupForm) => ({ - params: { - id: String(e.id), - }, - } - )); - return { - paths, - fallback: true, - }; -}; +export const getStaticPaths: GetStaticPaths = async () => ({ + paths: [], + fallback: "blocking", +}); export const getStaticProps: GetStaticProps = async ({ params }) => { - const { id } = params; - let notFound = false; - let initialForm: SignupForm; - try { - initialForm = await SignupApi.getForm(Number(id)); - } catch { - notFound = true; + const id = Number(params?.id); + if (!id) { + return { + notFound: true, + revalidate: 10, + }; + } + + try { + const initialForm = await SignupApi.getForm(id); + return { + props: { + initialForm, + }, + revalidate: 10, // Required for deleting hidden pages + }; + } catch { + return { + notFound: true, + revalidate: 10, + }; } - return { - props: { - initialForm, - }, - revalidate: 10, // Required for deleting hidden pages - notFound, - }; }; export default SignUpPage; diff --git a/src/pages/yritysyhteistyo.tsx b/src/pages/yritysyhteistyo.tsx index 6ae3c24..8676797 100644 --- a/src/pages/yritysyhteistyo.tsx +++ b/src/pages/yritysyhteistyo.tsx @@ -30,10 +30,13 @@ const CorporatePage: NextPage = ({ initialJobAds }) => { }; export const getStaticProps: GetStaticProps = async () => { - const initialJobAds = await fetcher(jobAdApi); + const jobAdsResult = await Promise.allSettled([ + fetcher(jobAdApi), + ]); + return { props: { - initialJobAds, + initialJobAds: jobAdsResult[0].status === "fulfilled" ? jobAdsResult[0].value : [], }, revalidate: 10, };