Skip to content

Commit 846857f

Browse files
authored
Merge pull request #571 from PotLock/staging
Staging to Prod
2 parents a47f00c + 70baf15 commit 846857f

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

src/pages/campaign/[campaignId]/index.tsx

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ReactElement, useMemo } from "react";
22

3-
import type { GetServerSideProps } from "next";
3+
import type { GetStaticPaths, GetStaticProps } from "next";
44
import { useRouter } from "next/router";
55

66
import { INDEXER_API_ENDPOINT_URL } from "@/common/_config";
@@ -51,12 +51,34 @@ CampaignPage.getLayout = function getLayout(page: ReactElement) {
5151
return <CampaignLayout>{page}</CampaignLayout>;
5252
};
5353

54-
export const getServerSideProps: GetServerSideProps<CampaignPageProps> = async (context) => {
55-
const { campaignId } = context.params as { campaignId?: string };
56-
const { res } = context;
54+
export const getStaticPaths: GetStaticPaths = async () => {
55+
try {
56+
const response = await fetch(`https://dev.potlock.io/api/v1/campaigns?page_size=200`, {
57+
headers: { "content-type": "application/json" },
58+
});
59+
60+
if (!response.ok) {
61+
return { paths: [], fallback: "blocking" };
62+
}
63+
64+
const payload = (await response.json()) as {
65+
results?: { on_chain_id: number | string }[];
66+
data?: { on_chain_id: number | string }[];
67+
};
5768

58-
// Cache SSR response at the edge to avoid repeated slow requests
59-
res.setHeader("Cache-Control", "s-maxage=300, stale-while-revalidate=900");
69+
const campaigns = payload.results ?? payload.data ?? [];
70+
71+
return {
72+
paths: campaigns.map((c) => ({ params: { campaignId: String(c.on_chain_id) } })),
73+
fallback: "blocking",
74+
};
75+
} catch {
76+
return { paths: [], fallback: "blocking" };
77+
}
78+
};
79+
80+
export const getStaticProps: GetStaticProps<CampaignPageProps> = async (context) => {
81+
const { campaignId } = context.params as { campaignId?: string };
6082
const parsedCampaignId = campaignId ? parseInt(campaignId) : undefined;
6183

6284
const fallbackSeo: SeoProps = {
@@ -98,9 +120,9 @@ export const getServerSideProps: GetServerSideProps<CampaignPageProps> = async (
98120
image: campaign?.cover_image_url ?? fallbackSeo.image,
99121
};
100122

101-
return { props: { seo } };
123+
return { props: { seo }, revalidate: 300 };
102124
} catch {
103-
return { props: { seo: fallbackSeo } };
125+
return { props: { seo: fallbackSeo }, revalidate: 60 };
104126
} finally {
105127
clearTimeout(timeoutId);
106128
}

0 commit comments

Comments
 (0)