mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-08-26 05:32:30 +02:00
fix: fix healthcheck
This commit is contained in:
+1
-1
@@ -81,7 +81,7 @@ services:
|
|||||||
healthcheck:
|
healthcheck:
|
||||||
test:
|
test:
|
||||||
- CMD
|
- CMD
|
||||||
- mongo
|
- mongosh
|
||||||
- --eval
|
- --eval
|
||||||
- "db.adminCommand('ping')"
|
- "db.adminCommand('ping')"
|
||||||
interval: 10s
|
interval: 10s
|
||||||
|
|||||||
+10
-6
@@ -1,22 +1,26 @@
|
|||||||
|
require("dotenv").config();
|
||||||
const http = require("http");
|
const http = require("http");
|
||||||
const config = require("./config");
|
const config = require("./build/config");
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
host: "localhost",
|
path: "/healthcheck",
|
||||||
port: config.PORT,
|
method: "GET",
|
||||||
|
host: "127.0.0.1",
|
||||||
|
port: config.default.PORT,
|
||||||
timeout: 2000,
|
timeout: 2000,
|
||||||
};
|
};
|
||||||
|
|
||||||
const request = http.request(options, (res) => {
|
const request = http.request(options, (res) => {
|
||||||
if (res.statusCode == 200) {
|
if (res.statusCode == 200 || res.statusCode == 404) {
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
} else {
|
} else {
|
||||||
|
const reqURL = `${res.req.protocol}://${res.req.host}:${options.port}${res.req.path}`;
|
||||||
|
console.log(reqURL, res.statusCode);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
request.on("error", (err) => {
|
request.on("error", (err) => {
|
||||||
console.log("ERROR");
|
console.log("ERROR", err);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -159,6 +159,9 @@ export default async function start() {
|
|||||||
stat = {};
|
stat = {};
|
||||||
}, 1000 * 60 * 60);
|
}, 1000 * 60 * 60);
|
||||||
|
|
||||||
|
apiRouter.get("/healthcheck", async (_, res) => {
|
||||||
|
res.json({ status: "ok" });
|
||||||
|
});
|
||||||
apiRouter.get("/stat", async (_, res) => {
|
apiRouter.get("/stat", async (_, res) => {
|
||||||
if (stat.nbRepositories) {
|
if (stat.nbRepositories) {
|
||||||
res.json(stat);
|
res.json(stat);
|
||||||
|
|||||||
@@ -16,6 +16,10 @@ app.use(compression());
|
|||||||
|
|
||||||
app.use("/api", router);
|
app.use("/api", router);
|
||||||
|
|
||||||
|
app.get("/healthcheck", async (_, res) => {
|
||||||
|
res.json({ status: "ok" });
|
||||||
|
});
|
||||||
|
|
||||||
app.all("*", (req, res) => {
|
app.all("*", (req, res) => {
|
||||||
handleError(
|
handleError(
|
||||||
new AnonymousError("file_not_found", {
|
new AnonymousError("file_not_found", {
|
||||||
|
|||||||
Reference in New Issue
Block a user