新增 YAML 配置解析(Bun 内置 YAML)、SQLite 数据存储(bun:sqlite)、按 interval 分组并发拨测引擎、REST API(/api/summary、/api/targets、/api/targets/:id/history、/api/targets/:id/trend)、React 前端 Dashboard(统计卡片、目标表格、可展开详情面板、recharts 趋势图)。CLI 简化为仅接受配置文件路径。移除 /api/demo 路由和相关 demo 代码。保留 /health、静态资源服务和 SPA fallback。
58 lines
1.1 KiB
TypeScript
58 lines
1.1 KiB
TypeScript
interface ChildProcessInfo {
|
|
name: string;
|
|
process: Bun.Subprocess;
|
|
}
|
|
|
|
const configPath = process.argv[2];
|
|
|
|
const env = {
|
|
...process.env,
|
|
BACKEND_PORT: process.env.PORT ?? "3000",
|
|
};
|
|
|
|
const children: ChildProcessInfo[] = [
|
|
{
|
|
name: "server",
|
|
process: Bun.spawn(["bun", "run", "dev:server", ...(configPath ? [configPath] : [])], {
|
|
env,
|
|
stdout: "inherit",
|
|
stderr: "inherit",
|
|
}),
|
|
},
|
|
{
|
|
name: "web",
|
|
process: Bun.spawn(["bun", "run", "dev:web"], {
|
|
env,
|
|
stdout: "inherit",
|
|
stderr: "inherit",
|
|
}),
|
|
},
|
|
];
|
|
|
|
const stopChildren = () => {
|
|
for (const child of children) {
|
|
child.process.kill();
|
|
}
|
|
};
|
|
|
|
process.on("SIGINT", () => {
|
|
stopChildren();
|
|
process.exit(130);
|
|
});
|
|
|
|
process.on("SIGTERM", () => {
|
|
stopChildren();
|
|
process.exit(143);
|
|
});
|
|
|
|
const firstExit = await Promise.race(
|
|
children.map(async (child) => ({ name: child.name, code: await child.process.exited })),
|
|
);
|
|
|
|
stopChildren();
|
|
|
|
if (firstExit.code !== 0) {
|
|
console.error(`${firstExit.name} exited with code ${firstExit.code}`);
|
|
process.exit(firstExit.code ?? 1);
|
|
}
|