Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
CoCo_Code_Op2
next.js
提交
764edc51
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,发现更多精彩内容 >>
未验证
提交
764edc51
编写于
3月 06, 2020
作者:
J
JJ Kasper
提交者:
GitHub
3月 06, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add identifier to NEXT_DATA when custom server is used (#10869)
上级
9edafc64
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
27 addition
and
1 deletion
+27
-1
packages/next/next-server/lib/utils.ts
packages/next/next-server/lib/utils.ts
+1
-0
packages/next/next-server/server/next-server.ts
packages/next/next-server/server/next-server.ts
+4
-0
packages/next/next-server/server/render.tsx
packages/next/next-server/server/render.tsx
+3
-0
packages/next/server/lib/start-server.ts
packages/next/server/lib/start-server.ts
+4
-1
test/integration/custom-server/test/index.test.js
test/integration/custom-server/test/index.test.js
+7
-0
test/integration/production/test/index.test.js
test/integration/production/test/index.test.js
+8
-0
未找到文件。
packages/next/next-server/lib/utils.ts
浏览文件 @
764edc51
...
...
@@ -80,6 +80,7 @@ export type NEXT_DATA = {
err
?:
Error
&
{
statusCode
?:
number
}
gsp
?:
boolean
gssp
?:
boolean
customServer
?:
boolean
}
/**
...
...
packages/next/next-server/server/next-server.ts
浏览文件 @
764edc51
...
...
@@ -91,6 +91,7 @@ export type ServerConstructor = {
*/
conf
?:
NextConfig
dev
?:
boolean
customServer
?:
boolean
}
export
default
class
Server
{
...
...
@@ -116,6 +117,7 @@ export default class Server {
hasCssMode
:
boolean
dev
?:
boolean
previewProps
:
__ApiPreviewProps
customServer
?:
boolean
}
private
compression
?:
Middleware
private
onErrorMiddleware
?:
({
err
}:
{
err
:
Error
})
=>
Promise
<
void
>
...
...
@@ -136,6 +138,7 @@ export default class Server {
quiet
=
false
,
conf
=
null
,
dev
=
false
,
customServer
=
true
,
}:
ServerConstructor
=
{})
{
this
.
dir
=
resolve
(
dir
)
this
.
quiet
=
quiet
...
...
@@ -167,6 +170,7 @@ export default class Server {
buildId
:
this
.
buildId
,
generateEtags
,
previewProps
:
this
.
getPreviewProps
(),
customServer
:
customServer
===
true
?
true
:
undefined
,
}
// Only the `publicRuntimeConfig` key is exposed to the client side
...
...
packages/next/next-server/server/render.tsx
浏览文件 @
764edc51
...
...
@@ -187,6 +187,7 @@ function renderDocument(
headTags
,
gsp
,
gssp
,
customServer
,
}:
RenderOpts
&
{
props
:
any
docProps
:
DocumentInitialProps
...
...
@@ -209,6 +210,7 @@ function renderDocument(
isFallback
?:
boolean
gsp
?:
boolean
gssp
?:
boolean
customServer
?:
boolean
}
):
string
{
return
(
...
...
@@ -231,6 +233,7 @@ function renderDocument(
err
:
err
?
serializeError
(
dev
,
err
)
:
undefined
,
// Error if one happened, otherwise don't sent in the resulting HTML
gsp
,
// whether the page is getStaticProps
gssp
,
// whether the page is getServerSideProps
customServer
,
// whether the user is using a custom server
},
dangerousAsPath
,
canonicalBase
,
...
...
packages/next/server/lib/start-server.ts
浏览文件 @
764edc51
...
...
@@ -6,7 +6,10 @@ export default async function start(
port
?:
number
,
hostname
?:
string
)
{
const
app
=
next
(
serverOptions
)
const
app
=
next
({
...
serverOptions
,
customServer
:
false
,
})
const
srv
=
http
.
createServer
(
app
.
getRequestHandler
())
await
new
Promise
((
resolve
,
reject
)
=>
{
// This code catches EADDRINUSE error if the port is already in use
...
...
test/integration/custom-server/test/index.test.js
浏览文件 @
764edc51
...
...
@@ -3,6 +3,7 @@
import
webdriver
from
'
next-webdriver
'
import
{
join
}
from
'
path
'
import
getPort
from
'
get-port
'
import
cheerio
from
'
cheerio
'
import
clone
from
'
clone
'
import
{
initNextServerScript
,
...
...
@@ -89,6 +90,12 @@ describe('Custom Server', () => {
const
html
=
await
renderViaHTTP
(
appPort
,
'
/dashboard
'
)
expect
(
html
).
toMatch
(
/made it to dashboard/
)
})
it
(
'
should contain customServer in NEXT_DATA
'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
appPort
,
'
/
'
)
const
$
=
cheerio
.
load
(
html
)
expect
(
JSON
.
parse
(
$
(
'
#__NEXT_DATA__
'
).
text
()).
customServer
).
toBe
(
true
)
})
})
describe
(
'
with generateEtags enabled
'
,
()
=>
{
...
...
test/integration/production/test/index.test.js
浏览文件 @
764edc51
...
...
@@ -239,6 +239,14 @@ describe('Production Usage', () => {
expect
(
html
).
toMatch
(
/404/
)
}
})
it
(
'
should not contain customServer in NEXT_DATA
'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
appPort
,
'
/
'
)
const
$
=
cheerio
.
load
(
html
)
expect
(
'
customServer
'
in
JSON
.
parse
(
$
(
'
#__NEXT_DATA__
'
).
text
())).
toBe
(
false
)
})
})
describe
(
'
API routes
'
,
()
=>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录