Skip to content

Commit 9857348

Browse files
authored
Merge pull request #523 from PotLock/campaign-server
done with campaign server
2 parents bca5161 + a2e6893 commit 9857348

File tree

3 files changed

+27
-96
lines changed

3 files changed

+27
-96
lines changed

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

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -32,37 +32,14 @@ CampaignPage.getLayout = function getLayout(page: ReactElement) {
3232
return <CampaignLayout>{page}</CampaignLayout>;
3333
};
3434

35-
// Pre-generate the most popular campaigns at build time
35+
// Don't pre-generate any paths at build time - generate on-demand to avoid timeouts
3636
export const getStaticPaths: GetStaticPaths = async () => {
37-
try {
38-
// Fetch campaigns to get IDs for pre-generation with timeout
39-
const res = await fetchWithTimeout(
40-
"https://dev.potlock.io/api/v1/campaigns?limit=50",
41-
{},
42-
8000, // 8 second timeout
43-
);
44-
45-
if (!res.ok) throw new Error(`Failed to fetch campaigns: ${res.status}`);
46-
const campaigns = await res.json();
47-
48-
// Generate paths for the first 50 campaigns (most recent/active)
49-
const paths =
50-
campaigns.data?.map((campaign: any) => ({
51-
params: { campaignId: campaign.on_chain_id.toString() },
52-
})) || [];
53-
54-
return {
55-
paths,
56-
fallback: "blocking", // Generate new pages on-demand if not pre-built
57-
};
58-
} catch (error) {
59-
console.error("Error generating static paths:", error);
60-
// Return empty paths but still allow blocking fallback for on-demand generation
61-
return {
62-
paths: [],
63-
fallback: "blocking",
64-
};
65-
}
37+
// Return empty paths - all pages will be generated on first request
38+
// This prevents build timeouts and serverless function timeouts
39+
return {
40+
paths: [],
41+
fallback: "blocking", // Generate pages on-demand when first visited, then cache
42+
};
6643
};
6744

6845
// Pre-build each campaign page with its data
@@ -112,8 +89,8 @@ export const getStaticProps: GetStaticProps<SeoProps> = async ({ params }) => {
11289

11390
return {
11491
props: { seoTitle, seoDescription, seoImage },
115-
// Revalidate every 5 minutes (300 seconds) to keep data fresh
116-
revalidate: 300,
92+
// Revalidate every 2 minutes (120 seconds) to keep data fresh
93+
revalidate: 120,
11794
};
11895
} catch (error) {
11996
console.error("Error generating static props:", error);

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

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -31,37 +31,14 @@ CampaignLeaderboardPage.getLayout = function getLayout(page: ReactElement) {
3131
return <CampaignLayout>{page}</CampaignLayout>;
3232
};
3333

34-
// Pre-generate the most popular campaigns at build time
34+
// Don't pre-generate any paths at build time - generate on-demand to avoid timeouts
3535
export const getStaticPaths: GetStaticPaths = async () => {
36-
try {
37-
// Fetch campaigns to get IDs for pre-generation with timeout
38-
const res = await fetchWithTimeout(
39-
"https://dev.potlock.io/api/v1/campaigns?limit=50",
40-
{},
41-
8000, // 8 second timeout
42-
);
43-
44-
if (!res.ok) throw new Error(`Failed to fetch campaigns: ${res.status}`);
45-
const campaigns = await res.json();
46-
47-
// Generate paths for the first 50 campaigns (most recent/active)
48-
const paths =
49-
campaigns.data?.map((campaign: any) => ({
50-
params: { campaignId: campaign.on_chain_id.toString() },
51-
})) || [];
52-
53-
return {
54-
paths,
55-
fallback: "blocking", // Generate new pages on-demand if not pre-built
56-
};
57-
} catch (error) {
58-
console.error("Error generating static paths:", error);
59-
// Return empty paths but still allow blocking fallback for on-demand generation
60-
return {
61-
paths: [],
62-
fallback: "blocking",
63-
};
64-
}
36+
// Return empty paths - all pages will be generated on first request
37+
// This prevents build timeouts and serverless function timeouts
38+
return {
39+
paths: [],
40+
fallback: "blocking", // Generate pages on-demand when first visited, then cache
41+
};
6542
};
6643

6744
// Pre-build each campaign page with its data
@@ -111,8 +88,8 @@ export const getStaticProps: GetStaticProps<SeoProps> = async ({ params }) => {
11188

11289
return {
11390
props: { seoTitle, seoDescription, seoImage },
114-
// Revalidate every 5 minutes (300 seconds) to keep data fresh
115-
revalidate: 300,
91+
// Revalidate every 2 minutes (120 seconds) to keep data fresh
92+
revalidate: 120,
11693
};
11794
} catch (error) {
11895
console.error("Error generating static props:", error);

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

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -31,37 +31,14 @@ CampaignSettingsPage.getLayout = function getLayout(page: ReactElement) {
3131
return <CampaignLayout>{page}</CampaignLayout>;
3232
};
3333

34-
// Pre-generate the most popular campaigns at build time
34+
// Don't pre-generate any paths at build time - generate on-demand to avoid timeouts
3535
export const getStaticPaths: GetStaticPaths = async () => {
36-
try {
37-
// Fetch campaigns to get IDs for pre-generation with timeout
38-
const res = await fetchWithTimeout(
39-
"https://dev.potlock.io/api/v1/campaigns?limit=50",
40-
{},
41-
8000, // 8 second timeout
42-
);
43-
44-
if (!res.ok) throw new Error(`Failed to fetch campaigns: ${res.status}`);
45-
const campaigns = await res.json();
46-
47-
// Generate paths for the first 50 campaigns (most recent/active)
48-
const paths =
49-
campaigns.data?.map((campaign: any) => ({
50-
params: { campaignId: campaign.on_chain_id.toString() },
51-
})) || [];
52-
53-
return {
54-
paths,
55-
fallback: "blocking", // Generate new pages on-demand if not pre-built
56-
};
57-
} catch (error) {
58-
console.error("Error generating static paths:", error);
59-
// Return empty paths but still allow blocking fallback for on-demand generation
60-
return {
61-
paths: [],
62-
fallback: "blocking",
63-
};
64-
}
36+
// Return empty paths - all pages will be generated on first request
37+
// This prevents build timeouts and serverless function timeouts
38+
return {
39+
paths: [],
40+
fallback: "blocking", // Generate pages on-demand when first visited, then cache
41+
};
6542
};
6643

6744
// Pre-build each campaign page with its data
@@ -111,8 +88,8 @@ export const getStaticProps: GetStaticProps<SeoProps> = async ({ params }) => {
11188

11289
return {
11390
props: { seoTitle, seoDescription, seoImage },
114-
// Revalidate every 5 minutes (300 seconds) to keep data fresh
115-
revalidate: 300,
91+
// Revalidate every 2 minutes (120 seconds) to keep data fresh
92+
revalidate: 120,
11693
};
11794
} catch (error) {
11895
console.error("Error generating static props:", error);

0 commit comments

Comments
 (0)