feat: DevTools 仪表盘新增自重启功能
- 新增 POST /api/devtools/restart 端点(spawn 新进程 + exit 旧进程) - 仪表盘服务状态卡片新增「🔁 重启 DevTools」按钮 - 重启流程:确认 → API 调用 → 2s 后自动刷新页面 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -215,6 +215,23 @@ app.get('/api/health', (_req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
// ---- DevTools 自重启 ----
|
||||
app.post('/api/devtools/restart', (_req, res) => {
|
||||
res.json({ success: true, message: 'DevTools 正在重启...' });
|
||||
|
||||
// 延迟 500ms 确保响应已发送,然后 spawn 新进程并退出
|
||||
setTimeout(() => {
|
||||
const scriptPath = path.join(__dirname, 'index.js');
|
||||
const child = spawn(process.execPath, [scriptPath, ...process.argv.slice(2)], {
|
||||
cwd: ROOT,
|
||||
detached: true,
|
||||
stdio: 'inherit',
|
||||
});
|
||||
child.unref();
|
||||
process.exit(0);
|
||||
}, 500);
|
||||
});
|
||||
|
||||
// ---- 仪表盘数据 (必须在 /api/services/:id 之前以避免路由冲突) ----
|
||||
app.get('/api/dashboard', async (_req, res) => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user