From c6f43ddd161a3a527f4051785ea04459aef991d5 Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Sun, 12 Jun 2022 22:20:29 +0800 Subject: [PATCH] fix: dont handle sigterm in middleware mode (#8550) Co-authored-by: patak --- packages/vite/src/node/server/index.ts | 32 +++++++++++++------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts index 33565d7390d601..fc66b909a33989 100644 --- a/packages/vite/src/node/server/index.ts +++ b/packages/vite/src/node/server/index.ts @@ -299,7 +299,6 @@ export async function createServer( const container = await createPluginContainer(config, moduleGraph, watcher) const closeHttpServer = createServerCloseFn(httpServer) - // eslint-disable-next-line prefer-const let exitProcess: () => void const server: ViteDevServer = { @@ -342,10 +341,11 @@ export async function createServer( return startServer(server, port, isRestart) }, async close() { - process.off('SIGTERM', exitProcess) - - if (!middlewareMode && process.env.CI !== 'true') { - process.stdin.off('end', exitProcess) + if (!middlewareMode) { + process.off('SIGTERM', exitProcess) + if (process.env.CI !== 'true') { + process.stdin.off('end', exitProcess) + } } await Promise.all([ @@ -382,18 +382,18 @@ export async function createServer( server.transformIndexHtml = createDevHtmlTransformFn(server) - exitProcess = async () => { - try { - await server.close() - } finally { - process.exit() + if (!middlewareMode) { + exitProcess = async () => { + try { + await server.close() + } finally { + process.exit() + } + } + process.once('SIGTERM', exitProcess) + if (process.env.CI !== 'true') { + process.stdin.on('end', exitProcess) } - } - - process.once('SIGTERM', exitProcess) - - if (!middlewareMode && process.env.CI !== 'true') { - process.stdin.on('end', exitProcess) } const { packageCache } = config