Added automatic port detection to support running multiple instances of the repo simultaneously on local machines. The system detects available ports and automatically configures environment variables. Changes: - Created scripts/detect-ports.js for automatic port detection - Created scripts/start-dev.js to orchestrate port detection and service startup - Updated dev command to use new port detection system - Modified server to use dynamic SERVER_PORT environment variable - Modified vite config to use dynamic VITE_PORT environment variable - Added dynamic CORS/trusted origins for ports 3000-3010 in development - Organized setup scripts into scripts/ folder 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
61 lines
1.4 KiB
JavaScript
61 lines
1.4 KiB
JavaScript
import { spawn } from 'node:child_process';
|
|
import { detectAndSetPorts } from './detect-ports.js';
|
|
|
|
async function startDev() {
|
|
try {
|
|
// Detect and set ports
|
|
const { vitePort, serverPort } = await detectAndSetPorts();
|
|
|
|
console.log('\n🚀 Starting development servers...\n');
|
|
|
|
// Start concurrently with the detected ports
|
|
const concurrentlyCmd = spawn(
|
|
'bunx',
|
|
[
|
|
'concurrently',
|
|
`"cd server && SERVER_PORT=${serverPort} bun dev"`,
|
|
`"cd server && bun workers:dev"`,
|
|
`"cd vite && VITE_PORT=${vitePort} bun dev"`,
|
|
`"cd shared && bun dev"`,
|
|
],
|
|
{
|
|
stdio: 'inherit',
|
|
shell: true,
|
|
env: {
|
|
...process.env,
|
|
VITE_PORT: vitePort.toString(),
|
|
SERVER_PORT: serverPort.toString(),
|
|
},
|
|
}
|
|
);
|
|
|
|
concurrentlyCmd.on('error', (error) => {
|
|
console.error('Failed to start development servers:', error);
|
|
process.exit(1);
|
|
});
|
|
|
|
concurrentlyCmd.on('exit', (code) => {
|
|
if (code !== 0) {
|
|
console.error(`Development servers exited with code ${code}`);
|
|
}
|
|
process.exit(code);
|
|
});
|
|
|
|
// Handle termination signals
|
|
process.on('SIGINT', () => {
|
|
console.log('\n\n🛑 Shutting down development servers...');
|
|
concurrentlyCmd.kill('SIGINT');
|
|
});
|
|
|
|
process.on('SIGTERM', () => {
|
|
console.log('\n\n🛑 Shutting down development servers...');
|
|
concurrentlyCmd.kill('SIGTERM');
|
|
});
|
|
} catch (error) {
|
|
console.error('Error starting development servers:', error);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
startDev();
|