Add /defenseurs endpoint to serve security status
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 <noreply@anthropic.com>
This commit is contained in:
parent
69fea95320
commit
9a4c5c7775
1 changed files with 16 additions and 1 deletions
17
index.js
17
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));
|
||||
|
|
|
|||
Loading…
Reference in a new issue