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