/_health endpoint now checks the database and redis connections
This commit is contained in:
@@ -90,8 +90,6 @@ async function start(id: number, disconnect: () => void) {
|
|||||||
// Apply default rate limit to all routes
|
// Apply default rate limit to all routes
|
||||||
app.use(defaultRateLimiter());
|
app.use(defaultRateLimiter());
|
||||||
|
|
||||||
// install health check endpoint for all services
|
|
||||||
router.get("/_health", (ctx) => (ctx.body = "OK"));
|
|
||||||
app.use(router.routes());
|
app.use(router.routes());
|
||||||
|
|
||||||
// loop through requested services at startup
|
// loop through requested services at startup
|
||||||
|
|||||||
@@ -6,9 +6,11 @@ import send from "koa-send";
|
|||||||
import userAgent, { UserAgentContext } from "koa-useragent";
|
import userAgent, { UserAgentContext } from "koa-useragent";
|
||||||
import { languages } from "@shared/i18n";
|
import { languages } from "@shared/i18n";
|
||||||
import { IntegrationType } from "@shared/types";
|
import { IntegrationType } from "@shared/types";
|
||||||
|
import { sequelize } from "@server/database/sequelize";
|
||||||
import env from "@server/env";
|
import env from "@server/env";
|
||||||
import { NotFoundError } from "@server/errors";
|
import { NotFoundError } from "@server/errors";
|
||||||
import { Integration } from "@server/models";
|
import { Integration } from "@server/models";
|
||||||
|
import RedisAdapter from "@server/redis";
|
||||||
import { opensearchResponse } from "@server/utils/opensearch";
|
import { opensearchResponse } from "@server/utils/opensearch";
|
||||||
import { getTeamFromContext } from "@server/utils/passport";
|
import { getTeamFromContext } from "@server/utils/passport";
|
||||||
import { robotsResponse } from "@server/utils/robots";
|
import { robotsResponse } from "@server/utils/robots";
|
||||||
@@ -116,6 +118,22 @@ router.get("/opensearch.xml", (ctx) => {
|
|||||||
ctx.body = opensearchResponse(ctx.request.URL.origin);
|
ctx.body = opensearchResponse(ctx.request.URL.origin);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.get("/_health", async (ctx) => {
|
||||||
|
try {
|
||||||
|
await sequelize.query("SELECT 1");
|
||||||
|
} catch (err) {
|
||||||
|
throw new Error("Database connection failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await RedisAdapter.defaultClient.ping();
|
||||||
|
} catch (err) {
|
||||||
|
throw new Error("Redis ping failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.body = "OK";
|
||||||
|
});
|
||||||
|
|
||||||
router.get("/s/:shareId", renderShare);
|
router.get("/s/:shareId", renderShare);
|
||||||
router.get("/s/:shareId/doc/:documentSlug", renderShare);
|
router.get("/s/:shareId/doc/:documentSlug", renderShare);
|
||||||
router.get("/s/:shareId/*", renderShare);
|
router.get("/s/:shareId/*", renderShare);
|
||||||
|
|||||||
Reference in New Issue
Block a user