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>
This commit is contained in:
@@ -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 {
|
||||
|
||||
+20
-23
@@ -14,14 +14,13 @@ interface InitialProps {
|
||||
|
||||
const EventPage: NextPage<InitialProps> = ({ event }) => {
|
||||
const router = useRouter();
|
||||
const { id } = router.query;
|
||||
|
||||
if (router.isFallback) return <LoadingView />;
|
||||
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<link rel="canonical" href={`${process.env.NEXT_PUBLIC_SITE_URL}/events/${id}`} />
|
||||
<link rel="canonical" href={`${process.env.NEXT_PUBLIC_SITE_URL}/events/${event.id}`} />
|
||||
</Head>
|
||||
<PageWrapper>
|
||||
<EventPageView event={event} />
|
||||
@@ -30,36 +29,34 @@ const EventPage: NextPage<InitialProps> = ({ 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<InitialProps> = 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
|
||||
notFound,
|
||||
};
|
||||
} catch {
|
||||
return {
|
||||
notFound: true,
|
||||
revalidate: 10,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export default EventPage;
|
||||
|
||||
+19
-23
@@ -14,14 +14,13 @@ interface InitialProps {
|
||||
|
||||
const FeedPage: NextPage<InitialProps> = ({ post }) => {
|
||||
const router = useRouter();
|
||||
const { id } = router.query;
|
||||
|
||||
if (router.isFallback) return <LoadingView />;
|
||||
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<link rel="canonical" href={`${process.env.NEXT_PUBLIC_SITE_URL}/feed/${id}`} />
|
||||
<link rel="canonical" href={`${process.env.NEXT_PUBLIC_SITE_URL}/feed/${post.id}`} />
|
||||
</Head>
|
||||
<PageWrapper>
|
||||
<FeedPageView post={post} />
|
||||
@@ -30,37 +29,34 @@ const FeedPage: NextPage<InitialProps> = ({ 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<InitialProps> = 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,
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
const post = await FeedApi.getPost(id);
|
||||
return {
|
||||
props: {
|
||||
post,
|
||||
},
|
||||
revalidate: 10, // Required for deleting hidden pages
|
||||
notFound,
|
||||
};
|
||||
} catch {
|
||||
return {
|
||||
notFound: true,
|
||||
revalidate: 10,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export default FeedPage;
|
||||
|
||||
@@ -44,12 +44,15 @@ const InEnglishPage: NextPage<InitialProps> = ({ initialEvents, initialFeed }) =
|
||||
};
|
||||
|
||||
export const getStaticProps: GetStaticProps<InitialProps> = async () => {
|
||||
const initialEvents = await fetcher<Event[]>(eventApi);
|
||||
const initialFeed = await fetcher<Post[]>(feedApi);
|
||||
const [eventsResult, feedResult] = await Promise.allSettled([
|
||||
fetcher<Event[]>(eventApi),
|
||||
fetcher<Post[]>(feedApi),
|
||||
]);
|
||||
|
||||
return {
|
||||
props: {
|
||||
initialEvents,
|
||||
initialFeed,
|
||||
initialEvents: eventsResult.status === "fulfilled" ? eventsResult.value : [],
|
||||
initialFeed: feedResult.status === "fulfilled" ? feedResult.value : [],
|
||||
},
|
||||
revalidate: 10,
|
||||
};
|
||||
|
||||
+7
-4
@@ -43,12 +43,15 @@ const FrontPage: NextPage<InitialProps> = ({ initialEvents, initialFeed }) => {
|
||||
};
|
||||
|
||||
export const getStaticProps: GetStaticProps<InitialProps> = async () => {
|
||||
const initialEvents = fetcher<Event[]>(eventApi);
|
||||
const initialFeed = fetcher<Post[]>(feedApi);
|
||||
const [eventsResult, feedResult] = await Promise.allSettled([
|
||||
fetcher<Event[]>(eventApi),
|
||||
fetcher<Post[]>(feedApi),
|
||||
]);
|
||||
|
||||
return {
|
||||
props: {
|
||||
initialEvents: await initialEvents,
|
||||
initialFeed: await initialFeed,
|
||||
initialEvents: eventsResult.status === "fulfilled" ? eventsResult.value : [],
|
||||
initialFeed: feedResult.status === "fulfilled" ? feedResult.value : [],
|
||||
},
|
||||
revalidate: 10,
|
||||
};
|
||||
|
||||
@@ -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<InitialProps> = ({ initialEvents, initialFeed }) => {
|
||||
};
|
||||
|
||||
export const getStaticProps: GetStaticProps<InitialProps> = async () => {
|
||||
const initialEvents = await EventApi.getEvents();
|
||||
const initialFeed = await FeedApi.getFeed();
|
||||
const [eventsResult, feedResult] = await Promise.allSettled([
|
||||
fetcher<Event[]>(eventApi),
|
||||
fetcher<Post[]>(feedApi),
|
||||
]);
|
||||
|
||||
return {
|
||||
props: {
|
||||
initialEvents,
|
||||
initialFeed,
|
||||
initialEvents: eventsResult.status === "fulfilled" ? eventsResult.value : [],
|
||||
initialFeed: feedResult.status === "fulfilled" ? feedResult.value : [],
|
||||
},
|
||||
revalidate: 10,
|
||||
};
|
||||
|
||||
+19
-21
@@ -112,36 +112,34 @@ const SignUpPage: NextPage<InitialProps> = ({ 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<InitialProps> = 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
|
||||
notFound,
|
||||
};
|
||||
} catch {
|
||||
return {
|
||||
notFound: true,
|
||||
revalidate: 10,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export default SignUpPage;
|
||||
|
||||
@@ -30,10 +30,13 @@ const CorporatePage: NextPage<InitialProps> = ({ initialJobAds }) => {
|
||||
};
|
||||
|
||||
export const getStaticProps: GetStaticProps<InitialProps> = async () => {
|
||||
const initialJobAds = await fetcher<JobAd[]>(jobAdApi);
|
||||
const jobAdsResult = await Promise.allSettled([
|
||||
fetcher<JobAd[]>(jobAdApi),
|
||||
]);
|
||||
|
||||
return {
|
||||
props: {
|
||||
initialJobAds,
|
||||
initialJobAds: jobAdsResult[0].status === "fulfilled" ? jobAdsResult[0].value : [],
|
||||
},
|
||||
revalidate: 10,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user