fix: fix healthcheck

This commit is contained in:
tdurieux
2024-04-05 13:11:43 +01:00
parent c940c98b6e
commit 9048b5c3b1
4 changed files with 18 additions and 7 deletions

View File

@@ -81,7 +81,7 @@ services:
healthcheck:
test:
- CMD
- mongo
- mongosh
- --eval
- "db.adminCommand('ping')"
interval: 10s

View File

@@ -1,22 +1,26 @@
require("dotenv").config();
const http = require("http");
const config = require("./config");
const config = require("./build/config");
const options = {
host: "localhost",
port: config.PORT,
path: "/healthcheck",
method: "GET",
host: "127.0.0.1",
port: config.default.PORT,
timeout: 2000,
};
const request = http.request(options, (res) => {
if (res.statusCode == 200) {
if (res.statusCode == 200 || res.statusCode == 404) {
process.exit(0);
} else {
const reqURL = `${res.req.protocol}://${res.req.host}:${options.port}${res.req.path}`;
console.log(reqURL, res.statusCode);
process.exit(1);
}
});
request.on("error", (err) => {
console.log("ERROR");
console.log("ERROR", err);
process.exit(1);
});

View File

@@ -159,6 +159,9 @@ export default async function start() {
stat = {};
}, 1000 * 60 * 60);
apiRouter.get("/healthcheck", async (_, res) => {
res.json({ status: "ok" });
});
apiRouter.get("/stat", async (_, res) => {
if (stat.nbRepositories) {
res.json(stat);

View File

@@ -16,6 +16,10 @@ app.use(compression());
app.use("/api", router);
app.get("/healthcheck", async (_, res) => {
res.json({ status: "ok" });
});
app.all("*", (req, res) => {
handleError(
new AnonymousError("file_not_found", {