From f55f1c535928f2fb51ac00c4eca5cf56dcb02170 Mon Sep 17 00:00:00 2001 From: m5r Date: Wed, 21 Jul 2021 12:00:43 +0800 Subject: [PATCH] cache pages --- src/pages/calls.tsx | 11 +++++++---- src/pages/keypad.tsx | 12 ++++++++++-- src/pages/messages/index.tsx | 5 +++++ src/pages/settings/index.tsx | 11 ++++++++++- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/pages/calls.tsx b/src/pages/calls.tsx index f5216cd..5707622 100644 --- a/src/pages/calls.tsx +++ b/src/pages/calls.tsx @@ -27,10 +27,13 @@ const Calls: NextPage = (props) => { }; export const getServerSideProps = withPageOnboardingRequired( - async (context, user) => { - return { - props: { userId: user.id, ddd: 23 as const }, - }; + async ({ res }) => { + res.setHeader( + "Cache-Control", + "private, s-maxage=15, stale-while-revalidate=59", + ); + + return { props: {} }; }, ); diff --git a/src/pages/keypad.tsx b/src/pages/keypad.tsx index 4da0249..0d09dae 100644 --- a/src/pages/keypad.tsx +++ b/src/pages/keypad.tsx @@ -50,7 +50,8 @@ const Keypad: NextPage = () => { -
+
@@ -117,6 +118,13 @@ const pressBackspaceAtom = atom( }, ); -export const getServerSideProps = withPageOnboardingRequired(); +export const getServerSideProps = withPageOnboardingRequired(({ res }) => { + res.setHeader( + "Cache-Control", + "private, s-maxage=15, stale-while-revalidate=59", + ); + + return { props: {} }; +}); export default Keypad; diff --git a/src/pages/messages/index.tsx b/src/pages/messages/index.tsx index 1c8da4d..634f562 100644 --- a/src/pages/messages/index.tsx +++ b/src/pages/messages/index.tsx @@ -49,6 +49,11 @@ type Recipient = string; export const getServerSideProps = withPageOnboardingRequired( async (context, user) => { + context.res.setHeader( + "Cache-Control", + "private, s-maxage=15, stale-while-revalidate=59", + ); + const [customer, messages] = await Promise.all([ findCustomer(user.id), findCustomerMessages(user.id), diff --git a/src/pages/settings/index.tsx b/src/pages/settings/index.tsx index c43a091..595514c 100644 --- a/src/pages/settings/index.tsx +++ b/src/pages/settings/index.tsx @@ -49,6 +49,15 @@ const Settings: NextPage = (props) => { ); }; -export const getServerSideProps = withPageOnboardingRequired(); +export const getServerSideProps = withPageOnboardingRequired( + async ({ res }) => { + res.setHeader( + "Cache-Control", + "private, s-maxage=15, stale-while-revalidate=59", + ); + + return { props: {} }; + }, +); export default Settings;