From a6ccbe3051c722f8c8ea423808aeeb16bae31c04 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Mon, 2 Oct 2023 15:16:50 -0400 Subject: [PATCH] feat(server): add simple health endpoint --- server.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/server.js b/server.js index a57f7f0fd7..288f75ccc2 100644 --- a/server.js +++ b/server.js @@ -18,7 +18,7 @@ const app = connect(); app.use( bodyParser.json({ deflate: true, - limit: "1mb" + limit: "1mb", }) ); app.use(compression()); @@ -30,7 +30,7 @@ const gitClone = (repoUrl) => { console.log("Cloning", repoUrl, "to", tempDir); const result = spawnSync("git", ["clone", repoUrl, "--depth", "1", tempDir], { encoding: "utf-8", - shell: false + shell: false, }); if (result.status !== 0 || result.error) { console.log(result.error); @@ -55,7 +55,7 @@ const parseQueryString = (q, body, options = {}) => { "projectVersion", "parentUUID", "serverUrl", - "apiKey" + "apiKey", ]; for (const param of queryParams) { @@ -88,6 +88,12 @@ const start = (options) => { .createServer(app) .listen(options.serverPort, options.serverHost); configureServer(cdxgenServer); + + app.use("/health", async function (req, res) { + res.setHeader("Content-Type", "application/json"); + res.end(JSON.stringify({ status: "OK" }, null, 2)); + }); + app.use("/sbom", async function (req, res) { const q = url.parse(req.url, true).query; let cleanup = false;