|
1 | 1 | import { ReactElement, useMemo } from "react"; |
2 | 2 |
|
3 | | -import type { GetStaticPaths, GetStaticProps } from "next"; |
| 3 | +import type { GetServerSideProps } from "next"; |
4 | 4 | import { useRouter } from "next/router"; |
5 | 5 |
|
6 | 6 | import { INDEXER_API_ENDPOINT_URL } from "@/common/_config"; |
@@ -51,13 +51,12 @@ CampaignPage.getLayout = function getLayout(page: ReactElement) { |
51 | 51 | return <CampaignLayout>{page}</CampaignLayout>; |
52 | 52 | }; |
53 | 53 |
|
54 | | -export const getStaticPaths: GetStaticPaths = async () => ({ |
55 | | - paths: [], |
56 | | - fallback: "blocking", |
57 | | -}); |
58 | | - |
59 | | -export const getStaticProps: GetStaticProps<CampaignPageProps> = async (context) => { |
| 54 | +export const getServerSideProps: GetServerSideProps<CampaignPageProps> = async (context) => { |
60 | 55 | const { campaignId } = context.params as { campaignId?: string }; |
| 56 | + const { res } = context; |
| 57 | + |
| 58 | + // Cache SSR response at the edge to avoid repeated slow requests |
| 59 | + res.setHeader("Cache-Control", "s-maxage=300, stale-while-revalidate=900"); |
61 | 60 | const parsedCampaignId = campaignId ? parseInt(campaignId) : undefined; |
62 | 61 |
|
63 | 62 | const fallbackSeo: SeoProps = { |
@@ -99,9 +98,9 @@ export const getStaticProps: GetStaticProps<CampaignPageProps> = async (context) |
99 | 98 | image: campaign?.cover_image_url ?? fallbackSeo.image, |
100 | 99 | }; |
101 | 100 |
|
102 | | - return { props: { seo }, revalidate: 300 }; |
| 101 | + return { props: { seo } }; |
103 | 102 | } catch { |
104 | | - return { props: { seo: fallbackSeo }, revalidate: 60 }; |
| 103 | + return { props: { seo: fallbackSeo } }; |
105 | 104 | } finally { |
106 | 105 | clearTimeout(timeoutId); |
107 | 106 | } |
|
0 commit comments