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));