Files
svelte-mud/production.js
2025-04-21 23:22:32 +02:00

46 lines
1.3 KiB
JavaScript

import { spawn } from 'child_process';
import { dirname } from 'path';
import { fileURLToPath } from 'url';
import { svelteKitPort } from './src/proxy-websocket-server.js';
const __dirname = dirname(fileURLToPath(import.meta.url));
// Start the SvelteKit production server on internal port
console.log(`Starting SvelteKit production server on internal port ${svelteKitPort}`);
const sveltekit = spawn('node', ['build/index.js'], {
stdio: 'inherit',
shell: true,
cwd: __dirname,
env: { ...process.env, PORT: svelteKitPort }
});
// Start the Proxy WebSocket server on the main port (3000)
console.log('Starting Proxy WebSocket server on public port 3000');
const proxyServer = spawn('node', ['src/proxy-websocket-server.js'], {
stdio: 'inherit',
shell: true,
cwd: __dirname
});
// Handle process exit
process.on('exit', () => {
console.log('Shutting down servers...');
proxyServer.kill();
sveltekit.kill();
});
// Handle ctrl+c
process.on('SIGINT', () => {
console.log('Received SIGINT, shutting down servers...');
proxyServer.kill('SIGINT');
sveltekit.kill('SIGINT');
process.exit(0);
});
// Handle termination
process.on('SIGTERM', () => {
console.log('Received SIGTERM, shutting down servers...');
proxyServer.kill('SIGTERM');
sveltekit.kill('SIGTERM');
process.exit(0);
});