CoastalCommitsPastes/client/pages/index.tsx

61 lines
1.5 KiB
TypeScript
Raw Normal View History

2022-03-12 23:40:28 -05:00
import styles from '@styles/Home.module.css'
import PageSeo from '@components/page-seo'
2022-03-24 21:03:57 -04:00
import HomeComponent from '@components/home'
import { Page, Text } from '@geist-ui/core'
import { GetServerSideProps } from 'next'
export const getServerSideProps: GetServerSideProps = async ({ res }) => {
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
const { title, content, rendered } = await resp.json()
res.setHeader(
'Cache-Control',
`public, s-maxage=${60 * 60 * 24 * 360}, max-age=${60 * 60 * 24 * 360}`
)
return {
props: {
introContent: content || null,
rendered: rendered || null,
introTitle: title || null,
}
}
} catch (error) {
return {
props: {
error: true
}
}
}
}
type Props = {
introContent: string
2022-03-24 18:44:12 -04:00
introTitle: string
2022-03-24 21:03:57 -04:00
rendered: string
error?: boolean
}
const Home = ({ rendered, introContent, introTitle, error }: Props) => {
2022-03-07 19:42:47 -05:00
return (
2022-03-24 21:03:57 -04:00
<Page className={styles.wrapper}>
2022-03-12 23:13:35 -05:00
<PageSeo />
<Page.Content className={styles.main}>
{error && <Text>Something went wrong. Is the server running?</Text>}
{!error && <HomeComponent rendered={rendered} introContent={introContent} introTitle={introTitle} />}
2022-03-07 19:42:47 -05:00
</Page.Content>
2022-03-12 23:13:35 -05:00
</Page>
2022-03-07 19:42:47 -05:00
)
}
export default Home