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
f6218305
Unverified
Commit
f6218305
authored
Apr 04, 2023
by
Jan Kaifer
Committed by
GitHub
Apr 04, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix issue where NextServer.prepare wouldn't be called when deployed (#47899)
parent
eba1626b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
11 deletions
+33
-11
base-server.ts
packages/next/src/server/base-server.ts
+13
-2
next-dev-server.ts
packages/next/src/server/dev/next-dev-server.ts
+2
-2
next-server.ts
packages/next/src/server/next-server.ts
+5
-2
next.ts
packages/next/src/server/next.ts
+13
-5
No files found.
packages/next/src/server/base-server.ts
View file @
f6218305
...
...
@@ -534,6 +534,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
res
:
BaseNextResponse
,
parsedUrl
?:
NextUrlWithParsedQuery
):
Promise
<
void
>
{
await
this
.
prepare
()
const
method
=
req
.
method
.
toUpperCase
()
return
getTracer
().
trace
(
BaseServerSpan
.
handleRequest
,
...
...
@@ -968,8 +969,18 @@ export default abstract class Server<ServerOptions extends Options = Options> {
this
.
renderOpts
.
assetPrefix
=
prefix
?
prefix
.
replace
(
/
\/
$/
,
''
)
:
''
}
// Backwards compatibility
public
async
prepare
():
Promise
<
void
>
{}
protected
preparedPromise
:
Promise
<
void
>
|
null
=
null
/**
* Runs async initialization of server.
* It is idempotent, won't fire underlying initialization more than once.
*/
public
async
prepare
():
Promise
<
void
>
{
if
(
this
.
preparedPromise
===
null
)
{
this
.
preparedPromise
=
this
.
prepareImpl
()
}
return
this
.
preparedPromise
}
protected
async
prepareImpl
():
Promise
<
void
>
{}
// Backwards compatibility
protected
async
close
():
Promise
<
void
>
{}
...
...
packages/next/src/server/dev/next-dev-server.ts
View file @
f6218305
...
...
@@ -873,7 +873,7 @@ export default class DevServer extends Server {
}
}
async
prepare
():
Promise
<
void
>
{
protected
async
prepareImpl
():
Promise
<
void
>
{
setGlobal
(
'distDir'
,
this
.
distDir
)
setGlobal
(
'phase'
,
PHASE_DEVELOPMENT_SERVER
)
...
...
@@ -907,7 +907,7 @@ export default class DevServer extends Server {
telemetry
,
})
}
await
super
.
prepare
()
await
super
.
prepare
Impl
()
await
this
.
addExportPathMapRoutes
()
await
this
.
hotReloader
?.
start
()
await
this
.
startWatcher
()
...
...
packages/next/src/server/next-server.ts
View file @
f6218305
...
...
@@ -327,8 +327,8 @@ export default class NextNodeServer extends BaseServer {
setHttpClientAndAgentOptions
(
this
.
nextConfig
)
}
p
ublic
async
prepare
()
{
await
super
.
prepare
()
p
rotected
async
prepareImpl
()
{
await
super
.
prepare
Impl
()
if
(
!
this
.
serverOptions
.
dev
&&
this
.
nextConfig
.
experimental
.
instrumentationHook
...
...
@@ -1639,6 +1639,9 @@ export default class NextNodeServer extends BaseServer {
}
public
getRequestHandler
():
NodeRequestHandler
{
// This is just optimization to fire prepare as soon as possible
// It will be properly awaited later
void
this
.
prepare
()
const
handler
=
super
.
getRequestHandler
()
return
async
(
req
,
res
,
parsedUrl
)
=>
{
return
handler
(
this
.
normalizeReq
(
req
),
this
.
normalizeRes
(
res
),
parsedUrl
)
...
...
packages/next/src/server/next.ts
View file @
f6218305
...
...
@@ -126,7 +126,12 @@ export class NextServer {
async
prepare
()
{
const
server
=
await
this
.
getServer
()
return
server
.
prepare
()
// We shouldn't prepare the server in production,
// because this code won't be executed when deployed
if
(
this
.
options
.
dev
)
{
await
server
.
prepare
()
}
}
async
close
()
{
...
...
@@ -135,12 +140,15 @@ export class NextServer {
}
private
async
createServer
(
options
:
DevServerOptions
):
Promise
<
Server
>
{
let
ServerImplementation
:
typeof
Server
if
(
options
.
dev
)
{
const
DevServer
=
require
(
'./dev/next-dev-server'
).
default
return
new
DevServer
(
options
)
ServerImplementation
=
require
(
'./dev/next-dev-server'
).
default
}
else
{
ServerImplementation
=
await
getServerImpl
()
}
const
ServerImplementation
=
await
getServerImpl
()
return
new
ServerImplementation
(
options
)
const
server
=
new
ServerImplementation
(
options
)
return
server
}
private
async
loadConfig
()
{
...
...
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