Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
764edc51
Unverified
Commit
764edc51
authored
Mar 06, 2020
by
JJ Kasper
Committed by
GitHub
Mar 06, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add identifier to NEXT_DATA when custom server is used (#10869)
parent
9edafc64
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
27 additions
and
1 deletion
+27
-1
utils.ts
packages/next/next-server/lib/utils.ts
+1
-0
next-server.ts
packages/next/next-server/server/next-server.ts
+4
-0
render.tsx
packages/next/next-server/server/render.tsx
+3
-0
start-server.ts
packages/next/server/lib/start-server.ts
+4
-1
index.test.js
test/integration/custom-server/test/index.test.js
+7
-0
index.test.js
test/integration/production/test/index.test.js
+8
-0
No files found.
packages/next/next-server/lib/utils.ts
View file @
764edc51
...
@@ -80,6 +80,7 @@ export type NEXT_DATA = {
...
@@ -80,6 +80,7 @@ export type NEXT_DATA = {
err
?:
Error
&
{
statusCode
?:
number
}
err
?:
Error
&
{
statusCode
?:
number
}
gsp
?:
boolean
gsp
?:
boolean
gssp
?:
boolean
gssp
?:
boolean
customServer
?:
boolean
}
}
/**
/**
...
...
packages/next/next-server/server/next-server.ts
View file @
764edc51
...
@@ -91,6 +91,7 @@ export type ServerConstructor = {
...
@@ -91,6 +91,7 @@ export type ServerConstructor = {
*/
*/
conf
?:
NextConfig
conf
?:
NextConfig
dev
?:
boolean
dev
?:
boolean
customServer
?:
boolean
}
}
export
default
class
Server
{
export
default
class
Server
{
...
@@ -116,6 +117,7 @@ export default class Server {
...
@@ -116,6 +117,7 @@ export default class Server {
hasCssMode
:
boolean
hasCssMode
:
boolean
dev
?:
boolean
dev
?:
boolean
previewProps
:
__ApiPreviewProps
previewProps
:
__ApiPreviewProps
customServer
?:
boolean
}
}
private
compression
?:
Middleware
private
compression
?:
Middleware
private
onErrorMiddleware
?:
({
err
}:
{
err
:
Error
})
=>
Promise
<
void
>
private
onErrorMiddleware
?:
({
err
}:
{
err
:
Error
})
=>
Promise
<
void
>
...
@@ -136,6 +138,7 @@ export default class Server {
...
@@ -136,6 +138,7 @@ export default class Server {
quiet
=
false
,
quiet
=
false
,
conf
=
null
,
conf
=
null
,
dev
=
false
,
dev
=
false
,
customServer
=
true
,
}:
ServerConstructor
=
{})
{
}:
ServerConstructor
=
{})
{
this
.
dir
=
resolve
(
dir
)
this
.
dir
=
resolve
(
dir
)
this
.
quiet
=
quiet
this
.
quiet
=
quiet
...
@@ -167,6 +170,7 @@ export default class Server {
...
@@ -167,6 +170,7 @@ export default class Server {
buildId
:
this
.
buildId
,
buildId
:
this
.
buildId
,
generateEtags
,
generateEtags
,
previewProps
:
this
.
getPreviewProps
(),
previewProps
:
this
.
getPreviewProps
(),
customServer
:
customServer
===
true
?
true
:
undefined
,
}
}
// Only the `publicRuntimeConfig` key is exposed to the client side
// Only the `publicRuntimeConfig` key is exposed to the client side
...
...
packages/next/next-server/server/render.tsx
View file @
764edc51
...
@@ -187,6 +187,7 @@ function renderDocument(
...
@@ -187,6 +187,7 @@ function renderDocument(
headTags
,
headTags
,
gsp
,
gsp
,
gssp
,
gssp
,
customServer
,
}:
RenderOpts
&
{
}:
RenderOpts
&
{
props
:
any
props
:
any
docProps
:
DocumentInitialProps
docProps
:
DocumentInitialProps
...
@@ -209,6 +210,7 @@ function renderDocument(
...
@@ -209,6 +210,7 @@ function renderDocument(
isFallback
?:
boolean
isFallback
?:
boolean
gsp
?:
boolean
gsp
?:
boolean
gssp
?:
boolean
gssp
?:
boolean
customServer
?:
boolean
}
}
):
string
{
):
string
{
return
(
return
(
...
@@ -231,6 +233,7 @@ function renderDocument(
...
@@ -231,6 +233,7 @@ function renderDocument(
err
:
err
?
serializeError
(
dev
,
err
)
:
undefined
,
// Error if one happened, otherwise don't sent in the resulting HTML
err
:
err
?
serializeError
(
dev
,
err
)
:
undefined
,
// Error if one happened, otherwise don't sent in the resulting HTML
gsp
,
// whether the page is getStaticProps
gsp
,
// whether the page is getStaticProps
gssp
,
// whether the page is getServerSideProps
gssp
,
// whether the page is getServerSideProps
customServer
,
// whether the user is using a custom server
},
},
dangerousAsPath
,
dangerousAsPath
,
canonicalBase
,
canonicalBase
,
...
...
packages/next/server/lib/start-server.ts
View file @
764edc51
...
@@ -6,7 +6,10 @@ export default async function start(
...
@@ -6,7 +6,10 @@ export default async function start(
port
?:
number
,
port
?:
number
,
hostname
?:
string
hostname
?:
string
)
{
)
{
const
app
=
next
(
serverOptions
)
const
app
=
next
({
...
serverOptions
,
customServer
:
false
,
})
const
srv
=
http
.
createServer
(
app
.
getRequestHandler
())
const
srv
=
http
.
createServer
(
app
.
getRequestHandler
())
await
new
Promise
((
resolve
,
reject
)
=>
{
await
new
Promise
((
resolve
,
reject
)
=>
{
// This code catches EADDRINUSE error if the port is already in use
// This code catches EADDRINUSE error if the port is already in use
...
...
test/integration/custom-server/test/index.test.js
View file @
764edc51
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
import
webdriver
from
'next-webdriver'
import
webdriver
from
'next-webdriver'
import
{
join
}
from
'path'
import
{
join
}
from
'path'
import
getPort
from
'get-port'
import
getPort
from
'get-port'
import
cheerio
from
'cheerio'
import
clone
from
'clone'
import
clone
from
'clone'
import
{
import
{
initNextServerScript
,
initNextServerScript
,
...
@@ -89,6 +90,12 @@ describe('Custom Server', () => {
...
@@ -89,6 +90,12 @@ describe('Custom Server', () => {
const
html
=
await
renderViaHTTP
(
appPort
,
'/dashboard'
)
const
html
=
await
renderViaHTTP
(
appPort
,
'/dashboard'
)
expect
(
html
).
toMatch
(
/made it to 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'
,
()
=>
{
describe
(
'with generateEtags enabled'
,
()
=>
{
...
...
test/integration/production/test/index.test.js
View file @
764edc51
...
@@ -239,6 +239,14 @@ describe('Production Usage', () => {
...
@@ -239,6 +239,14 @@ describe('Production Usage', () => {
expect
(
html
).
toMatch
(
/404/
)
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'
,
()
=>
{
describe
(
'API routes'
,
()
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment