rsnext/examples/ssr-caching/pages/index.tsx

28 lines
563 B
TypeScript
Raw Normal View History

import { GetServerSideProps, InferGetServerSidePropsType } from 'next'
export default function Index({
time,
}: InferGetServerSidePropsType<typeof getServerSideProps>) {
return (
<main>
<h1>SSR Caching with Next.js</h1>
<time dateTime={time}>{time}</time>
</main>
)
}
export const getServerSideProps: GetServerSideProps<{ time: string }> = async ({
res,
}) => {
res.setHeader(
'Cache-Control',
'public, s-maxage=10, stale-while-revalidate=59'
)
return {
props: {
time: new Date().toISOString(),
},
}
}