fix(node-agent): replace express with built-in http — no external deps needed

This commit is contained in:
Zac Gaetano 2026-05-20 22:59:03 -04:00
parent 21d31f1678
commit cc8ee63639

View file

@ -1,6 +1,6 @@
import express from 'express'; import http from 'http';
import os from 'os'; import os from 'os';
import fs from 'fs'; import fs from 'fs';
const MAM_API_URL = (process.env.MAM_API_URL || 'http://localhost:3000').replace(/\/$/, ''); const MAM_API_URL = (process.env.MAM_API_URL || 'http://localhost:3000').replace(/\/$/, '');
const NODE_TOKEN = process.env.NODE_TOKEN || ''; const NODE_TOKEN = process.env.NODE_TOKEN || '';
@ -9,18 +9,20 @@ const AGENT_PORT = parseInt(process.env.AGENT_PORT || '3002', 10);
const HEARTBEAT_MS = parseInt(process.env.HEARTBEAT_MS || '30000', 10); const HEARTBEAT_MS = parseInt(process.env.HEARTBEAT_MS || '30000', 10);
const VERSION = '1.0.0'; const VERSION = '1.0.0';
const app = express(); const server = http.createServer((req, res) => {
app.use(express.json()); if (req.method === 'GET' && req.url === '/health') {
res.writeHead(200, { 'Content-Type': 'application/json' });
// ── Health ──────────────────────────────────────────────────────────────── res.end(JSON.stringify({
app.get('/health', (_req, res) => { ok: true,
res.json({ hostname: os.hostname(),
ok: true, uptime: Math.round(process.uptime()),
hostname: os.hostname(), version: VERSION,
uptime: Math.round(process.uptime()), role: NODE_ROLE,
version: VERSION, }));
role: NODE_ROLE, } else {
}); res.writeHead(404);
res.end();
}
}); });
// ── CPU sampling (500ms window) ─────────────────────────────────────────── // ── CPU sampling (500ms window) ───────────────────────────────────────────
@ -51,8 +53,7 @@ function getIp() {
} }
// ── Hardware detection ──────────────────────────────────────────────────── // ── Hardware detection ────────────────────────────────────────────────────
// GPU_COUNT env var overrides filesystem detection (useful when /dev not mapped into container) // GPU_COUNT / BMD_COUNT env vars override filesystem detection when /dev isn't mapped
// BMD_COUNT env var similarly overrides Blackmagic DeckLink detection
function detectHardware() { function detectHardware() {
const capabilities = { gpus: [], blackmagic: [] }; const capabilities = { gpus: [], blackmagic: [] };
@ -134,7 +135,7 @@ async function heartbeat() {
heartbeat(); heartbeat();
setInterval(heartbeat, HEARTBEAT_MS); setInterval(heartbeat, HEARTBEAT_MS);
app.listen(AGENT_PORT, () => { server.listen(AGENT_PORT, () => {
console.log(`wild-dragon-node-agent v${VERSION}`); console.log(`wild-dragon-node-agent v${VERSION}`);
console.log(` Listening :${AGENT_PORT}`); console.log(` Listening :${AGENT_PORT}`);
console.log(` Primary ${MAM_API_URL}`); console.log(` Primary ${MAM_API_URL}`);