Initial commit
This commit is contained in:
44
start-server.js
Normal file
44
start-server.js
Normal file
@@ -0,0 +1,44 @@
|
||||
import { spawn } from 'child_process';
|
||||
import { dirname } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
// Start the WebSocket server
|
||||
console.log('Starting WebSocket server');
|
||||
const wsServer = spawn('node', ['src/websocket-server.js'], {
|
||||
stdio: 'inherit',
|
||||
shell: true,
|
||||
cwd: __dirname
|
||||
});
|
||||
|
||||
// Start the SvelteKit dev server
|
||||
console.log('Starting SvelteKit dev server');
|
||||
const sveltekit = spawn('npm', ['run', 'dev'], {
|
||||
stdio: 'inherit',
|
||||
shell: true,
|
||||
cwd: __dirname
|
||||
});
|
||||
|
||||
// Handle process exit
|
||||
process.on('exit', () => {
|
||||
console.log('Shutting down servers...');
|
||||
wsServer.kill();
|
||||
sveltekit.kill();
|
||||
});
|
||||
|
||||
// Handle ctrl+c
|
||||
process.on('SIGINT', () => {
|
||||
console.log('Received SIGINT, shutting down servers...');
|
||||
wsServer.kill('SIGINT');
|
||||
sveltekit.kill('SIGINT');
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
// Handle termination
|
||||
process.on('SIGTERM', () => {
|
||||
console.log('Received SIGTERM, shutting down servers...');
|
||||
wsServer.kill('SIGTERM');
|
||||
sveltekit.kill('SIGTERM');
|
||||
process.exit(0);
|
||||
});
|
||||
Reference in New Issue
Block a user