Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[legacy-framework] Fix custom-server hot reload on first run #2698

Merged
merged 2 commits into from
Sep 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 26 additions & 24 deletions packages/server/src/next-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,30 +253,32 @@ export function startCustomServer(
})
}

if (watch) {
// Handle build & Starting server
const esbuildOptions = getEsbuildOptions()
esbuildOptions.watch = {
onRebuild(error) {
if (error) {
log.error("Failed to re-build custom server")
} else {
newline()
log.progress("Custom server changed - restarting...")
newline()
//@ts-ignore -- incorrect TS type from node
process.exitCode = RESTART_CODE
process.kill("SIGABRT")
}
},
}
// eslint-disable-next-line @typescript-eslint/no-floating-promises
esbuild.build(esbuildOptions).then(() => {
spawnServer()
})
} else {
// No build required, Start server
spawnServer()
const skipDevCustomServerBuild = config.env === 'prod';

if (skipDevCustomServerBuild) {
spawnServer();
return;
}

// Handle build & Starting server
const esbuildOptions = getEsbuildOptions()
esbuildOptions.watch = watch ? {
onRebuild(error) {
if (error) {
log.error("Failed to re-build custom server")
} else {
newline()
log.progress("Custom server changed - restarting...")
newline()
//@ts-ignore -- incorrect TS type from node
process.exitCode = RESTART_CODE
process.kill("SIGABRT")
}
},
} : undefined
// eslint-disable-next-line @typescript-eslint/no-floating-promises
esbuild.build(esbuildOptions).then(() => {
spawnServer()
})
})
}