2022-04-09 20:48:19 -04:00
|
|
|
import styles from "@styles/Home.module.css"
|
|
|
|
import PageSeo from "@components/page-seo"
|
|
|
|
import HomeComponent from "@components/home"
|
2022-11-09 21:38:05 -05:00
|
|
|
import { Page, Text } from "@geist-ui/core/dist"
|
2022-04-19 21:05:21 -04:00
|
|
|
import type { GetStaticProps } from "next"
|
2022-04-22 01:01:59 -04:00
|
|
|
import { InferGetStaticPropsType } from "next"
|
|
|
|
type Props =
|
|
|
|
| {
|
|
|
|
introContent: string
|
|
|
|
introTitle: string
|
|
|
|
rendered: string
|
|
|
|
}
|
|
|
|
| {
|
|
|
|
error: boolean
|
|
|
|
}
|
2022-03-08 19:39:24 -05:00
|
|
|
|
2022-04-19 21:05:21 -04:00
|
|
|
export const getStaticProps: GetStaticProps = async () => {
|
2022-04-09 20:48:19 -04:00
|
|
|
try {
|
|
|
|
const resp = await fetch(process.env.API_URL + `/welcome`, {
|
|
|
|
method: "GET",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
"x-secret-key": process.env.SECRET_KEY || ""
|
|
|
|
}
|
|
|
|
})
|
2022-03-24 21:03:57 -04:00
|
|
|
|
2022-04-09 20:48:19 -04:00
|
|
|
const { title, content, rendered } = await resp.json()
|
|
|
|
return {
|
|
|
|
props: {
|
|
|
|
introContent: content || null,
|
|
|
|
rendered: rendered || null,
|
|
|
|
introTitle: title || null
|
2022-04-19 21:05:21 -04:00
|
|
|
},
|
|
|
|
// Next.js will attempt to re-generate the page:
|
|
|
|
// - When a request comes in
|
|
|
|
// - At most every 60 seconds
|
2022-04-22 01:01:59 -04:00
|
|
|
revalidate: 60 // In seconds
|
2022-04-09 20:48:19 -04:00
|
|
|
}
|
2022-04-19 21:05:21 -04:00
|
|
|
} catch (err) {
|
|
|
|
// If there was an error, it's likely due to the server not running, so we attempt to regenerate the page
|
2022-04-09 20:48:19 -04:00
|
|
|
return {
|
|
|
|
props: {
|
2022-04-22 01:01:59 -04:00
|
|
|
error: true
|
2022-04-19 21:05:21 -04:00
|
|
|
},
|
2022-04-22 01:01:59 -04:00
|
|
|
revalidate: 10 // In seconds
|
2022-04-09 20:48:19 -04:00
|
|
|
}
|
|
|
|
}
|
2022-03-08 19:39:24 -05:00
|
|
|
}
|
|
|
|
|
2022-04-19 21:05:21 -04:00
|
|
|
// TODO: fix props type
|
2022-04-22 01:01:59 -04:00
|
|
|
const Home = ({
|
|
|
|
rendered,
|
|
|
|
introContent,
|
|
|
|
introTitle,
|
|
|
|
error
|
|
|
|
}: InferGetStaticPropsType<typeof getStaticProps>) => {
|
2022-04-09 20:48:19 -04:00
|
|
|
return (
|
|
|
|
<Page className={styles.wrapper}>
|
|
|
|
<PageSeo />
|
|
|
|
<Page.Content className={styles.main}>
|
|
|
|
{error && <Text>Something went wrong. Is the server running?</Text>}
|
|
|
|
{!error && (
|
|
|
|
<HomeComponent
|
|
|
|
rendered={rendered}
|
|
|
|
introContent={introContent}
|
|
|
|
introTitle={introTitle}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</Page.Content>
|
|
|
|
</Page>
|
|
|
|
)
|
2022-03-07 19:42:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export default Home
|