Unverified Commit 84afda6b authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Update cache-control header when no getInitialProps (#7185)

parent dc47c607
...@@ -133,7 +133,9 @@ export async function loadGetInitialProps<C extends BaseContext, IP = {}, P = {} ...@@ -133,7 +133,9 @@ export async function loadGetInitialProps<C extends BaseContext, IP = {}, P = {}
if (!Component.getInitialProps) { if (!Component.getInitialProps) {
if (ctx.res && ctx.res.setHeader) { if (ctx.res && ctx.res.setHeader) {
ctx.res.setHeader('Cache-Control', 'stale-while-revalidate=30') ctx.res.setHeader(
'Cache-Control', 's-maxage=86400, stale-while-revalidate',
)
} }
return null return null
} }
......
...@@ -62,6 +62,13 @@ describe('Production Usage', () => { ...@@ -62,6 +62,13 @@ describe('Production Usage', () => {
expect(header).toBe('Next.js') expect(header).toBe('Next.js')
}) })
it('should set correct cache-control header when no GIP', async () => {
const url = `http://localhost:${appPort}/`
const header = (await fetch(url)).headers.get('Cache-Control')
expect(header).toBe('s-maxage=86400, stale-while-revalidate')
})
it('should render 404 for routes that do not exist', async () => { it('should render 404 for routes that do not exist', async () => {
const url = `http://localhost:${appPort}/abcdefghijklmno` const url = `http://localhost:${appPort}/abcdefghijklmno`
const res = await fetch(url) const res = await fetch(url)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment