-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathstart.js
More file actions
79 lines (60 loc) · 1.74 KB
/
start.js
File metadata and controls
79 lines (60 loc) · 1.74 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env node
import { spawn } from 'child_process';
import { resolve, dirname } from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
function startLLMGateway() {
const isWindows = process.platform === 'win32';
const tsxCmd = isWindows ? 'npx.cmd' : 'npx';
const llmGateway = spawn(tsxCmd, ['tsx', 'watch', 'src/index.ts'], {
cwd: __dirname,
stdio: 'inherit',
shell: true,
});
llmGateway.on('error', (error) => {
console.error('✗ LLM Gateway 启动失败:', error);
process.exit(1);
});
return llmGateway;
}
function startWebUI() {
const isWindows = process.platform === 'win32';
const npmCmd = isWindows ? 'npm.cmd' : 'npm';
const webUI = spawn(npmCmd, ['run', 'dev'], {
cwd: resolve(__dirname, 'web'),
stdio: 'inherit',
shell: true,
});
webUI.on('error', (error) => {
console.error('✗ Web UI 启动失败:', error);
process.exit(1);
});
return webUI;
}
async function main() {
console.log('启动 LLM Gateway...\n');
const llmGateway = startLLMGateway();
await new Promise(resolve => setTimeout(resolve, 3000));
const webUI = startWebUI();
console.log('\n启动完成!');
console.log('Web UI: http://0.0.0.0:5173');
console.log('API: http://0.0.0.0:3000');
console.log('按 Ctrl+C 停止服务\n');
process.on('SIGINT', () => {
console.log('\n正在停止服务...');
llmGateway.kill();
webUI.kill();
process.exit(0);
});
process.on('SIGTERM', () => {
console.log('\n正在停止服务...');
llmGateway.kill();
webUI.kill();
process.exit(0);
});
}
main().catch((error) => {
console.error('启动失败:', error);
process.exit(1);
});