Files
sapien/server/dev.js
2026-05-13 22:19:37 -05:00

33 lines
765 B
JavaScript

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))