fix: 第二轮修复 — 数据库启动检查、会话持久化、URL路由、设备排序等
1. DevTools 启动前检查数据库状态,失败时自动尝试启动 2. ai-core 添加数据库断线重连机制 (30秒间隔) 3. Dashboard 添加数据库状态卡片 (启动/停止/重启) 4. Gateway 会话空闲超时管理 (30分钟标记空闲) 5. 会话/消息 PostgreSQL 持久化 (SessionStore + REST API) 6. 前端服务端会话持久化 + URL hash 路由 + 侧边栏管理 7. 管理员回到主对话按钮 8. IoT 设备卡片固定排序 9. 更新相关文档
This commit is contained in:
@@ -696,6 +696,82 @@ app.post('/api/tunnel/:action', (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// ---- 数据库控制 (Docker Compose) ----
|
||||
const DB_COMPOSE_FILE = path.join(ROOT, 'docker-compose.dev.db.yml');
|
||||
const DB_PORT = 5432;
|
||||
|
||||
// GET /api/db/status
|
||||
app.get('/api/db/status', (_req, res) => {
|
||||
try {
|
||||
const online = checkPort(DB_PORT);
|
||||
res.json({
|
||||
online,
|
||||
port: DB_PORT,
|
||||
checked_at: new Date().toISOString(),
|
||||
});
|
||||
} catch (err) {
|
||||
res.json({
|
||||
online: false,
|
||||
port: DB_PORT,
|
||||
checked_at: new Date().toISOString(),
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// POST /api/db/start
|
||||
app.post('/api/db/start', (_req, res) => {
|
||||
try {
|
||||
const out = execSync(`docker compose -f "${DB_COMPOSE_FILE}" up -d`, {
|
||||
encoding: 'utf-8',
|
||||
timeout: 60000,
|
||||
stdio: 'pipe',
|
||||
});
|
||||
res.json({ success: true, action: 'start', output: out.trim() });
|
||||
} catch (err) {
|
||||
const stderr = err.stderr?.toString() || err.message;
|
||||
res.status(500).json({ success: false, action: 'start', error: stderr });
|
||||
}
|
||||
});
|
||||
|
||||
// POST /api/db/stop
|
||||
app.post('/api/db/stop', (_req, res) => {
|
||||
try {
|
||||
const out = execSync(`docker compose -f "${DB_COMPOSE_FILE}" down`, {
|
||||
encoding: 'utf-8',
|
||||
timeout: 30000,
|
||||
stdio: 'pipe',
|
||||
});
|
||||
res.json({ success: true, action: 'stop', output: out.trim() });
|
||||
} catch (err) {
|
||||
const stderr = err.stderr?.toString() || err.message;
|
||||
res.status(500).json({ success: false, action: 'stop', error: stderr });
|
||||
}
|
||||
});
|
||||
|
||||
// POST /api/db/restart
|
||||
app.post('/api/db/restart', (_req, res) => {
|
||||
try {
|
||||
const downOut = execSync(`docker compose -f "${DB_COMPOSE_FILE}" down`, {
|
||||
encoding: 'utf-8',
|
||||
timeout: 30000,
|
||||
stdio: 'pipe',
|
||||
});
|
||||
const upOut = execSync(`docker compose -f "${DB_COMPOSE_FILE}" up -d`, {
|
||||
encoding: 'utf-8',
|
||||
timeout: 60000,
|
||||
stdio: 'pipe',
|
||||
});
|
||||
res.json({
|
||||
success: true,
|
||||
action: 'restart',
|
||||
output: `down: ${downOut.trim()}\nup: ${upOut.trim()}`,
|
||||
});
|
||||
} catch (err) {
|
||||
const stderr = err.stderr?.toString() || err.message;
|
||||
res.status(500).json({ success: false, action: 'restart', error: stderr });
|
||||
}
|
||||
});
|
||||
|
||||
// ========== 启动 ==========
|
||||
// 启动性能监控
|
||||
performanceMonitor.start();
|
||||
|
||||
Reference in New Issue
Block a user