import { spawn } from 'node:child_process' const processes = [ spawn(process.execPath, ['server/server.js'], { stdio: 'inherit', env: { ...process.env, PORT: process.env.PORT || '3001' }, }), spawn(process.execPath, ['node_modules/vite/bin/vite.js', '--host'], { stdio: 'inherit', env: process.env, }), ] let isShuttingDown = false const shutdown = (code = 0) => { if (isShuttingDown) return isShuttingDown = true for (const child of processes) { if (!child.killed) child.kill('SIGTERM') } process.exit(code) } for (const child of processes) { child.on('exit', (code) => { if (!isShuttingDown && code !== 0) shutdown(code || 1) }) } process.on('SIGINT', () => shutdown(0)) process.on('SIGTERM', () => shutdown(0))