Skip to content

Commit

Permalink
feat(server): add simple health endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
setchy committed Oct 2, 2023
1 parent 2e3bc38 commit a6ccbe3
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const app = connect();
app.use(
bodyParser.json({
deflate: true,
limit: "1mb"
limit: "1mb",
})
);
app.use(compression());
Expand All @@ -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);
Expand All @@ -55,7 +55,7 @@ const parseQueryString = (q, body, options = {}) => {
"projectVersion",
"parentUUID",
"serverUrl",
"apiKey"
"apiKey",
];

for (const param of queryParams) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit a6ccbe3

Please sign in to comment.