From f1088cf8eff16602548c7c8a5373e424e0a7aaf4 Mon Sep 17 00:00:00 2001 From: Fernando Lucchesi Date: Fri, 20 Oct 2023 13:52:00 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9A=97=EF=B8=8F=20Explicity=20set=20cache=20?= =?UTF-8?q?policy=20for=20SSR=20pages=20#1944?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/pages/magasin/index.global.tsx | 4 +++- web/pages/magazine/index.global.tsx | 4 +++- web/pages/news/index.global.tsx | 6 ++++-- web/pages/nyheter/index.global.tsx | 5 ++++- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/web/pages/magasin/index.global.tsx b/web/pages/magasin/index.global.tsx index 9b69e1c03..905119b3b 100644 --- a/web/pages/magasin/index.global.tsx +++ b/web/pages/magasin/index.global.tsx @@ -71,12 +71,14 @@ MagazineIndexNorwegian.getLayout = (page: AppProps) => { ) } -export const getServerSideProps: GetServerSideProps = async ({ req, preview = false, locale = 'no' }) => { +export const getServerSideProps: GetServerSideProps = async ({ res, req, preview = false, locale = 'no' }) => { // For the time being, let's just give 404 for satellites // We will also return 404 if the locale is not Norwegian. // This is a hack and and we should improve this at some point // See https://github.com/vercel/next.js/discussions/18485 + res.setHeader('Cache-Control', 'private, no-cache, no-store, max-age=0, must-revalidate') + if (locale !== 'no') { return { notFound: true, diff --git a/web/pages/magazine/index.global.tsx b/web/pages/magazine/index.global.tsx index 2c66fd642..305189f83 100644 --- a/web/pages/magazine/index.global.tsx +++ b/web/pages/magazine/index.global.tsx @@ -66,12 +66,14 @@ MagazineIndex.getLayout = (page: AppProps) => { ) } -export const getServerSideProps: GetServerSideProps = async ({ req, preview = false, locale = 'en' }) => { +export const getServerSideProps: GetServerSideProps = async ({ res, req, preview = false, locale = 'en' }) => { // For the time being, let's just give 404 for satellites // We will also return 404 if the locale is not English. // This is a hack and and we should improve this at some point // See https://github.com/vercel/next.js/discussions/18485 + res.setHeader('Cache-Control', 'private, no-cache, no-store, max-age=0, must-revalidate') + if (locale !== 'en') { return { notFound: true, diff --git a/web/pages/news/index.global.tsx b/web/pages/news/index.global.tsx index 3adfe8719..472dd19a1 100644 --- a/web/pages/news/index.global.tsx +++ b/web/pages/news/index.global.tsx @@ -1,4 +1,4 @@ -import { GetServerSideProps } from 'next' +import { GetServerSideProps, GetStaticPaths } from 'next' import { InstantSearchSSRProvider } from 'react-instantsearch-hooks-web' import { getServerState } from 'react-instantsearch-hooks-server' import type { AppProps } from 'next/app' @@ -67,12 +67,14 @@ NewsRoom.getLayout = (page: AppProps) => { ) } -export const getServerSideProps: GetServerSideProps = async ({ req, preview = false, locale = 'en' }) => { +export const getServerSideProps: GetServerSideProps = async ({ res, req, preview = false, locale = 'en' }) => { // For the time being, let's just give 404 for satellites // We will also return 404 if the locale is not English. // This is a hack and and we should improve this at some point // See https://github.com/vercel/next.js/discussions/18485 + res.setHeader('Cache-Control', 'private, no-cache, no-store, max-age=0, must-revalidate') + if (locale !== 'en') { return { notFound: true, diff --git a/web/pages/nyheter/index.global.tsx b/web/pages/nyheter/index.global.tsx index 24fc2d633..44ad4a074 100644 --- a/web/pages/nyheter/index.global.tsx +++ b/web/pages/nyheter/index.global.tsx @@ -65,11 +65,14 @@ NorwegianNewsRoom.getLayout = (page: AppProps) => { ) } -export const getServerSideProps: GetServerSideProps = async ({ req, preview = false, locale = 'no' }) => { +export const getServerSideProps: GetServerSideProps = async ({ res, req, preview = false, locale = 'no' }) => { // For the time being, let's just give 404 for satellites // We will also return 404 if the locale is not Norwegian. // This is a hack, and we should improve this at some point // See https://github.com/vercel/next.js/discussions/18485 + + res.setHeader('Cache-Control', 'private, no-cache, no-store, max-age=0, must-revalidate') + if (locale !== 'no') { return { notFound: true,