-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathweb.ts
More file actions
39 lines (33 loc) · 1005 Bytes
/
web.ts
File metadata and controls
39 lines (33 loc) · 1005 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { spawn } from 'child_process';
import { join } from 'path';
import { createServer } from 'vite';
import { startServer } from './server';
const isProduction = process.env.NODE_ENV === 'production';
async function startDevServer(port: number) {
if (isProduction) {
startServer(port);
} else {
// Development: start backend as a child process
const api = spawn('bun', ['run', 'web.ts', '--backend-only'], {
env: { ...process.env, BACKEND_ONLY: 'true' },
stdio: 'inherit', // Share console output
});
// Development: start Vite
const vite = await createServer({
configFile: join(process.cwd(), 'vite.config.ts'),
});
await vite.listen();
console.log(`[VITE] Dev server running at http://localhost:${port}`);
// Cleanup on exit
process.on('SIGINT', () => {
api.kill();
vite.close();
process.exit();
});
}
}
if (process.env.BACKEND_ONLY === 'true') {
startServer(3001);
} else {
startDevServer(3000);
}