File tree Expand file tree Collapse file tree 1 file changed +15
-5
lines changed
Expand file tree Collapse file tree 1 file changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -79,16 +79,26 @@ export function nitroPreviewPlugin(ctx: NitroPluginContext): VitePlugin {
7979 PORT : String ( randomPort ) ,
8080 } ,
8181 } ) ;
82+
83+ const killChild = ( signal : NodeJS . Signals ) => {
84+ if ( child && ! child . killed ) {
85+ child . kill ( signal ) ;
86+ }
87+ } ;
88+
8289 for ( const sig of [ "SIGINT" , "SIGHUP" ] as const ) {
8390 process . once ( sig , ( ) => {
8491 consola . info ( `Stopping preview server...` ) ;
85- if ( child . killed === false ) {
86- child . kill ( sig ) ;
87- process . exit ( ) ;
88- }
92+ killChild ( sig ) ;
93+ process . exit ( ) ;
8994 } ) ;
9095 }
91- child . on ( "exit" , ( code ) => {
96+
97+ server . httpServer . once ( "close" , ( ) => {
98+ killChild ( "SIGTERM" ) ;
99+ } ) ;
100+
101+ child . once ( "exit" , ( code ) => {
92102 if ( code && code !== 0 ) {
93103 consola . error ( `[nitro] Preview server exited with code ${ code } ` ) ;
94104 }
You can’t perform that action at this time.
0 commit comments