-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathswr.tsx
34 lines (30 loc) · 847 Bytes
/
swr.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { GetServerSideProps, InferGetServerSidePropsType } from "next";
import Nav from "~/components/Nav";
export default function SWR({
time,
}: InferGetServerSidePropsType<typeof getServerSideProps>) {
return (
<main>
<Nav title="Stale-while-revalidate" />
<h1>Stale-while-revalidate</h1>
<p>This page contains the following cache headers:</p>
<code>Cache-Control: public, s-maxage=10, stale-while-revalidate=59</code>
<br />
<p>This page was last revalidated:</p>
<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(),
},
};
};