/** * @file host.js * @description `GET /api/host` — the Dashboard System Health tab's machine * cards, its per-user CPU/RAM card included: the machine's hardware, load and * disks, and each AgentHub user's share of its CPU and memory right now * (server/lib/host-stats.js); `GET /api/host/history` (`?range=1h|6h|24h`) the * in-memory CPU/memory history the server keeps since it started. Read-only; * every signed-in user (`/host` is NOT in STAFF_ONLY_PREFIXES — System Health * is everyone's). * @author Nguyễn Ngọc Trí Vĩ */ const { Router } = require("express"); const { hostStats, hostHistory } = require("../lib/host-stats"); const router = Router(); router.get("/", async (_req, res) => { try { res.json(await hostStats()); } catch (e) { res.status(500).json({ error: { code: "EHOST", message: e.message } }); } }); router.get("/history", (req, res) => { res.json(hostHistory(typeof req.query.range === "string" ? req.query.range : "1h")); }); module.exports = router;