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"
|
|
|
|
import { Page, Text } from "@geist-ui/core"
|
|
|
|
import { GetServerSideProps } from "next"
|
2022-03-08 19:39:24 -05:00
|
|
|
|
2022-04-06 13:41:42 -04:00
|
|
|
export const getServerSideProps: GetServerSideProps = async ({ res }) => {
|
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()
|
2022-04-06 13:41:42 -04:00
|
|
|
|
2022-04-09 20:48:19 -04:00
|
|
|
res.setHeader(
|
|
|
|
"Cache-Control",
|
|
|
|
`public, s-maxage=${60 * 60 * 24 * 360}, max-age=${60 * 60 * 24 * 360}`
|
|
|
|
)
|
2022-04-06 13:41:42 -04:00
|
|
|
|
2022-04-09 20:48:19 -04:00
|
|
|
return {
|
|
|
|
props: {
|
|
|
|
introContent: content || null,
|
|
|
|
rendered: rendered || null,
|
|
|
|
introTitle: title || null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
return {
|
|
|
|
props: {
|
|
|
|
error: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-03-08 19:39:24 -05:00
|
|
|
}
|
|
|
|
|
2022-03-22 23:06:15 -04:00
|
|
|
type Props = {
|
2022-04-09 20:48:19 -04:00
|
|
|
introContent: string
|
|
|
|
introTitle: string
|
|
|
|
rendered: string
|
|
|
|
error?: boolean
|
2022-03-08 19:39:24 -05:00
|
|
|
}
|
|
|
|
|
2022-04-02 03:45:26 -04:00
|
|
|
const Home = ({ rendered, introContent, introTitle, error }: Props) => {
|
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
|