Skip to content

Commit e997006

Browse files
committed
fix: only call server.close() if still listening
1 parent f165789 commit e997006

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/node/cli-start.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { cac } from 'cac'
2+
import consola from 'consola'
23
import { name, version } from '../../package.json'
34
import { build, serve } from './index'
45

@@ -30,11 +31,14 @@ export async function startCli(cwd = process.cwd(), argv = process.argv) {
3031
.action(async (file: string, options: { watch: false | string | string[] }) => {
3132
const server = await serve({ cwd, entry: file, ...options })
3233

33-
process.on('SIGINT', () => server.close())
34-
process.on('exit', () => server.close())
35-
process.on('uncaughtException', () => {
34+
const close = () => server.httpServer?.listening && server.close()
35+
36+
process.on('SIGINT', () => close())
37+
process.on('exit', () => close())
38+
process.on('uncaughtException', (err) => {
39+
consola.error(err)
3640
process.exitCode = 1
37-
server.close()
41+
close()
3842
})
3943
})
4044

0 commit comments

Comments
 (0)