From 08b4abb01ad1fbc0f03b0f18f3cc0b691bacc356 Mon Sep 17 00:00:00 2001 From: LeriusLei <140469515+LeriusLei@users.noreply.github.com> Date: Fri, 20 Mar 2026 12:11:32 -0500 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20/healthz=20?= =?UTF-8?q?=E5=81=A5=E5=BA=B7=E6=A3=80=E6=9F=A5=E4=B8=8E=E8=BF=90=E8=A1=8C?= =?UTF-8?q?=E6=97=B6=E8=AF=8A=E6=96=AD=E7=AB=AF=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在 server/src/main.js 新增只读 GET /healthz 端点, 返回服务状态、版本号、运行时长、地图加载状态、 当前玩家数和 SSE 连接数,便于云端部署监控。 Closes #9 Co-Authored-By: Claude Sonnet 4.6 --- server/src/main.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/server/src/main.js b/server/src/main.js index 6716af89..406c84bc 100644 --- a/server/src/main.js +++ b/server/src/main.js @@ -67,4 +67,16 @@ io.on('connection', (socket) => { socket.emit('characterList', worldEngine.getCharacterList()); }); +// ── 健康检查与运行时诊断 ────────────────────────────────────────────────────── +app.get('/healthz', (_req, res) => { + res.json({ + status: 'ok', + version: require('../package.json').version, + uptime: Math.floor(process.uptime()), + mapLoaded: worldEngine.getWorldMap() !== null, + playerCount: Object.keys(worldEngine.getAllPlayers()).length, + sseClients: sseClients.length, + }); +}); + server.listen(PORT, () => console.log(`🌍 Underworld 已启动: http://localhost:${PORT}`));