Skip to content

Commit

Permalink
fix: build crashes upon rendering static pages
Browse files Browse the repository at this point in the history
  • Loading branch information
skinmaker1345 committed Oct 12, 2024
1 parent 831b025 commit dae36eb
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pages/bots/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import dynamic from 'next/dynamic'
import { Bot, List } from '@types'
import * as Query from '@utils/Query'
import LongButton from '@components/LongButton'
import { PHASE_PRODUCTION_BUILD } from 'next/constants'

const Advertisement = dynamic(() => import('@components/Advertisement'))
const ResponsiveGrid = dynamic(() => import('@components/ResponsiveGrid'))
Expand Down Expand Up @@ -66,6 +67,21 @@ const Index: NextPage<IndexProps> = ({ votes, newBots, trusted }) => {
}

export const getStaticProps = async () => {
if (process.env.NEXT_PHASE === PHASE_PRODUCTION_BUILD) {
const list = {
totalPage: 1,
currentPage: 1,
data: [],
}
return {
props: {
votes: list,
newBots: list,
trusted: list,
},
revalidate: 1,
}
}
const votes = await Query.get.list.votes.load(1)
const newBots = await Query.get.list.new.load(1)
const trusted = await Query.get.list.trusted.load(1)
Expand Down
15 changes: 15 additions & 0 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import dynamic from 'next/dynamic'

import { Bot, List, Server } from '@types'
import * as Query from '@utils/Query'
import { PHASE_PRODUCTION_BUILD } from 'next/constants'

const Advertisement = dynamic(() => import('@components/Advertisement'))
const ResponsiveGrid = dynamic(() => import('@components/ResponsiveGrid'))
Expand Down Expand Up @@ -50,6 +51,20 @@ const Index: NextPage<IndexProps> = ({ bots, servers }) => {
}

export const getStaticProps = async () => {
if (process.env.NEXT_PHASE === PHASE_PRODUCTION_BUILD) {
const list = {
totalPage: 1,
currentPage: 1,
data: [],
}
return {
props: {
bots: list,
servers: list,
},
revalidate: 1,
}
}
const bots = await Query.get.list.votes.load(1)
const servers = await Query.get.serverList.votes.load(1)

Expand Down
9 changes: 9 additions & 0 deletions pages/security.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import dynamic from 'next/dynamic'
import { User } from '@types'
import { BUG_REPORTERS, BUG_REPORT_GROUPS } from '@utils/Constants'
import { get } from '@utils/Query'
import { PHASE_PRODUCTION_BUILD } from 'next/constants'

const Docs = dynamic(() => import('@components/Docs'))
const DiscordAvatar = dynamic(() => import('@components/DiscordAvatar'))
Expand Down Expand Up @@ -88,6 +89,14 @@ const Security: NextPage<SecurityProps> = ({ bugReports }) => {
}

export const getStaticProps: GetStaticProps<SecurityProps> = async () => {
if (process.env.NEXT_PHASE === PHASE_PRODUCTION_BUILD) {
return {
props: {
bugReports: [],
},
revalidate: 1,
}
}
return {
props: {
bugReports: await Promise.all(BUG_REPORTERS.map((u) => get.user.load(u))),
Expand Down
15 changes: 15 additions & 0 deletions pages/servers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import dynamic from 'next/dynamic'

import { Server, List } from '@types'
import * as Query from '@utils/Query'
import { PHASE_PRODUCTION_BUILD } from 'next/constants'

const Advertisement = dynamic(() => import('@components/Advertisement'))
const ResponsiveGrid = dynamic(() => import('@components/ResponsiveGrid'))
Expand Down Expand Up @@ -48,6 +49,20 @@ const ServerIndex: NextPage<ServerIndexProps> = ({ votes, trusted }) => {
}

export const getStaticProps = async () => {
if (process.env.NEXT_PHASE === PHASE_PRODUCTION_BUILD) {
const list = {
totalPage: 1,
currentPage: 1,
data: [],
}
return {
props: {
votes: list,
trusted: list,
},
revalidate: 1,
}
}
const votes = await Query.get.serverList.votes.load(1)
const trusted = await Query.get.serverList.trusted.load(1)

Expand Down

0 comments on commit dae36eb

Please sign in to comment.