Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
CoCo_Code_Op2
next.js
提交
b5d8767f
N
next.js
项目概览
CoCo_Code_Op2
/
next.js
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
N
next.js
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
b5d8767f
编写于
10月 22, 2019
作者:
J
Joe Haddad
提交者:
GitHub
10月 22, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Cache No-Revalidate Pages (#9170)
* Cache No-Revalidate Pages * Specifically check for `false`
上级
c0a1c0f9
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
34 addition
and
12 deletion
+34
-12
packages/next/next-server/server/next-server.ts
packages/next/next-server/server/next-server.ts
+15
-9
test/integration/prerender/test/index.test.js
test/integration/prerender/test/index.test.js
+19
-3
未找到文件。
packages/next/next-server/server/next-server.ts
浏览文件 @
b5d8767f
...
@@ -4,6 +4,7 @@ import { IncomingMessage, ServerResponse } from 'http'
...
@@ -4,6 +4,7 @@ import { IncomingMessage, ServerResponse } from 'http'
import
{
join
,
resolve
,
sep
}
from
'
path
'
import
{
join
,
resolve
,
sep
}
from
'
path
'
import
{
parse
as
parseQs
,
ParsedUrlQuery
}
from
'
querystring
'
import
{
parse
as
parseQs
,
ParsedUrlQuery
}
from
'
querystring
'
import
{
parse
as
parseUrl
,
UrlWithParsedQuery
}
from
'
url
'
import
{
parse
as
parseUrl
,
UrlWithParsedQuery
}
from
'
url
'
import
{
withCoalescedInvoke
}
from
'
../../lib/coalesced-function
'
import
{
withCoalescedInvoke
}
from
'
../../lib/coalesced-function
'
import
{
import
{
BUILD_ID_FILE
,
BUILD_ID_FILE
,
...
@@ -22,7 +23,7 @@ import {
...
@@ -22,7 +23,7 @@ import {
isDynamicRoute
,
isDynamicRoute
,
}
from
'
../lib/router/utils
'
}
from
'
../lib/router/utils
'
import
*
as
envConfig
from
'
../lib/runtime-config
'
import
*
as
envConfig
from
'
../lib/runtime-config
'
import
{
NextApiRequest
,
NextApiResponse
,
isResSent
}
from
'
../lib/utils
'
import
{
isResSent
,
NextApiRequest
,
NextApiResponse
}
from
'
../lib/utils
'
import
{
apiResolver
}
from
'
./api-utils
'
import
{
apiResolver
}
from
'
./api-utils
'
import
loadConfig
,
{
isTargetLikeServerless
}
from
'
./config
'
import
loadConfig
,
{
isTargetLikeServerless
}
from
'
./config
'
import
{
recursiveReadDirSync
}
from
'
./lib/recursive-readdir-sync
'
import
{
recursiveReadDirSync
}
from
'
./lib/recursive-readdir-sync
'
...
@@ -32,9 +33,8 @@ import { getPagePath } from './require'
...
@@ -32,9 +33,8 @@ import { getPagePath } from './require'
import
Router
,
{
Params
,
route
,
Route
,
RouteMatch
}
from
'
./router
'
import
Router
,
{
Params
,
route
,
Route
,
RouteMatch
}
from
'
./router
'
import
{
sendHTML
}
from
'
./send-html
'
import
{
sendHTML
}
from
'
./send-html
'
import
{
serveStatic
}
from
'
./serve-static
'
import
{
serveStatic
}
from
'
./serve-static
'
import
{
getSprCache
,
initializeSprCache
,
setSprCache
}
from
'
./spr-cache
'
import
{
isBlockedPage
,
isInternalUrl
}
from
'
./utils
'
import
{
isBlockedPage
,
isInternalUrl
}
from
'
./utils
'
import
{
findPagesDir
}
from
'
../../lib/find-pages-dir
'
import
{
initializeSprCache
,
getSprCache
,
setSprCache
}
from
'
./spr-cache
'
type
NextConfig
=
any
type
NextConfig
=
any
...
@@ -542,12 +542,18 @@ export default class Server {
...
@@ -542,12 +542,18 @@ export default class Server {
// TODO: ETag? Cache-Control headers? Next-specific headers?
// TODO: ETag? Cache-Control headers? Next-specific headers?
res
.
setHeader
(
'
Content-Type
'
,
type
)
res
.
setHeader
(
'
Content-Type
'
,
type
)
res
.
setHeader
(
'
Content-Length
'
,
Buffer
.
byteLength
(
payload
))
res
.
setHeader
(
'
Content-Length
'
,
Buffer
.
byteLength
(
payload
))
if
(
!
this
.
renderOpts
.
dev
)
{
if
(
revalidate
)
{
if
(
revalidate
)
{
res
.
setHeader
(
res
.
setHeader
(
'
Cache-Control
'
,
'
Cache-Control
'
,
`s-maxage=
${
revalidate
}
, stale-while-revalidate`
`s-maxage=
${
revalidate
}
, stale-while-revalidate`
)
)
}
else
if
(
revalidate
===
false
)
{
res
.
setHeader
(
'
Cache-Control
'
,
`s-maxage=31536000, stale-while-revalidate`
)
}
}
}
res
.
end
(
payload
)
res
.
end
(
payload
)
}
}
...
...
test/integration/prerender/test/index.test.js
浏览文件 @
b5d8767f
...
@@ -5,6 +5,7 @@ import { join } from 'path'
...
@@ -5,6 +5,7 @@ import { join } from 'path'
import
webdriver
from
'
next-webdriver
'
import
webdriver
from
'
next-webdriver
'
import
{
import
{
renderViaHTTP
,
renderViaHTTP
,
fetchViaHTTP
,
findPort
,
findPort
,
launchApp
,
launchApp
,
killApp
,
killApp
,
...
@@ -202,14 +203,20 @@ const runTests = (dev = false) => {
...
@@ -202,14 +203,20 @@ const runTests = (dev = false) => {
if
(
dev
)
{
if
(
dev
)
{
it
(
'
should always call getStaticProps without caching in dev
'
,
async
()
=>
{
it
(
'
should always call getStaticProps without caching in dev
'
,
async
()
=>
{
const
initialHtml
=
await
renderViaHTTP
(
appPort
,
'
/something
'
)
const
initialRes
=
await
fetchViaHTTP
(
appPort
,
'
/something
'
)
expect
(
initialRes
.
headers
.
get
(
'
cache-control
'
)).
toBeFalsy
()
const
initialHtml
=
await
initialRes
.
text
()
expect
(
initialHtml
).
toMatch
(
/hello.*
?
world/
)
expect
(
initialHtml
).
toMatch
(
/hello.*
?
world/
)
const
newHtml
=
await
renderViaHTTP
(
appPort
,
'
/something
'
)
const
newRes
=
await
fetchViaHTTP
(
appPort
,
'
/something
'
)
expect
(
newRes
.
headers
.
get
(
'
cache-control
'
)).
toBeFalsy
()
const
newHtml
=
await
newRes
.
text
()
expect
(
newHtml
).
toMatch
(
/hello.*
?
world/
)
expect
(
newHtml
).
toMatch
(
/hello.*
?
world/
)
expect
(
initialHtml
!==
newHtml
).
toBe
(
true
)
expect
(
initialHtml
!==
newHtml
).
toBe
(
true
)
const
newerHtml
=
await
renderViaHTTP
(
appPort
,
'
/something
'
)
const
newerRes
=
await
fetchViaHTTP
(
appPort
,
'
/something
'
)
expect
(
newerRes
.
headers
.
get
(
'
cache-control
'
)).
toBeFalsy
()
const
newerHtml
=
await
newerRes
.
text
()
expect
(
newerHtml
).
toMatch
(
/hello.*
?
world/
)
expect
(
newerHtml
).
toMatch
(
/hello.*
?
world/
)
expect
(
newHtml
!==
newerHtml
).
toBe
(
true
)
expect
(
newHtml
!==
newerHtml
).
toBe
(
true
)
})
})
...
@@ -230,6 +237,15 @@ const runTests = (dev = false) => {
...
@@ -230,6 +237,15 @@ const runTests = (dev = false) => {
}
}
})
})
}
else
{
}
else
{
it
(
'
should should use correct caching headers for a no-revalidate page
'
,
async
()
=>
{
const
initialRes
=
await
fetchViaHTTP
(
appPort
,
'
/something
'
)
expect
(
initialRes
.
headers
.
get
(
'
cache-control
'
)).
toBe
(
'
s-maxage=31536000, stale-while-revalidate
'
)
const
initialHtml
=
await
initialRes
.
text
()
expect
(
initialHtml
).
toMatch
(
/hello.*
?
world/
)
})
it
(
'
outputs a prerender-manifest correctly
'
,
async
()
=>
{
it
(
'
outputs a prerender-manifest correctly
'
,
async
()
=>
{
const
manifest
=
JSON
.
parse
(
const
manifest
=
JSON
.
parse
(
await
fs
.
readFile
(
join
(
appDir
,
'
.next/prerender-manifest.json
'
),
'
utf8
'
)
await
fs
.
readFile
(
join
(
appDir
,
'
.next/prerender-manifest.json
'
),
'
utf8
'
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录