未验证 提交 84afda6b 编写于 作者: J JJ Kasper 提交者: GitHub

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

上级 dc47c607
......@@ -133,7 +133,9 @@ export async function loadGetInitialProps<C extends BaseContext, IP = {}, P = {}
if (!Component.getInitialProps) {
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
}
......
......@@ -62,6 +62,13 @@ describe('Production Usage', () => {
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 () => {
const url = `http://localhost:${appPort}/abcdefghijklmno`
const res = await fetch(url)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册