From 9a4c5c7775d4cfc589fd3ae36a33bb4cd8d9e635 Mon Sep 17 00:00:00 2001 From: le king fu Date: Wed, 4 Mar 2026 20:13:10 -0500 Subject: [PATCH] Add /defenseurs endpoint to serve security status MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reads status.json written by the sergent (Escouade Défenseur) from a Docker volume mount path. Used by the admin dashboard. Co-Authored-By: Claude Opus 4.6 --- index.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index fe2da39..1e9252b 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,7 @@ const http = require("node:http"); const os = require("node:os"); const { execSync } = require("node:child_process"); +const { readFileSync } = require("node:fs"); const PORT = parseInt(process.env.PORT || "3001", 10); const TOKEN = process.env.HEALTH_TOKEN; @@ -82,7 +83,8 @@ function getHealth() { const server = http.createServer((req, res) => { res.setHeader("Content-Type", "application/json"); - if (req.url !== "/health" || req.method !== "GET") { + const validRoutes = ["/health", "/defenseurs"]; + if (req.method !== "GET" || !validRoutes.includes(req.url)) { res.writeHead(404); res.end(JSON.stringify({ error: "Not found" })); return; @@ -101,6 +103,19 @@ const server = http.createServer((req, res) => { return; } + if (req.url === "/defenseurs") { + const statusPath = process.env.DEFENSEURS_STATUS_PATH || "/data/defenseurs/status.json"; + try { + const status = readFileSync(statusPath, "utf-8"); + res.writeHead(200); + res.end(status); + } catch { + res.writeHead(200); + res.end(JSON.stringify({ status: "no_data" })); + } + return; + } + const data = getHealth(); res.writeHead(200); res.end(JSON.stringify(data));