Move health check endpoint back to server root
This commit is contained in:
@@ -26,6 +26,8 @@ import {
|
||||
import { checkUpdates } from "./utils/updates";
|
||||
import onerror from "./onerror";
|
||||
import ShutdownHelper, { ShutdownOrder } from "./utils/ShutdownHelper";
|
||||
import { sequelize } from "./database/sequelize";
|
||||
import RedisAdapter from "./redis";
|
||||
|
||||
// The default is to run all services to make development and OSS installations
|
||||
// easier to deal with. Separate services are only needed at scale.
|
||||
@@ -90,6 +92,23 @@ async function start(id: number, disconnect: () => void) {
|
||||
// Apply default rate limit to all routes
|
||||
app.use(defaultRateLimiter());
|
||||
|
||||
// Add a health check endpoint to all services
|
||||
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";
|
||||
});
|
||||
|
||||
app.use(router.routes());
|
||||
|
||||
// loop through requested services at startup
|
||||
|
||||
@@ -6,11 +6,9 @@ import send from "koa-send";
|
||||
import userAgent, { UserAgentContext } from "koa-useragent";
|
||||
import { languages } from "@shared/i18n";
|
||||
import { IntegrationType } from "@shared/types";
|
||||
import { sequelize } from "@server/database/sequelize";
|
||||
import env from "@server/env";
|
||||
import { NotFoundError } from "@server/errors";
|
||||
import { Integration } from "@server/models";
|
||||
import RedisAdapter from "@server/redis";
|
||||
import { opensearchResponse } from "@server/utils/opensearch";
|
||||
import { getTeamFromContext } from "@server/utils/passport";
|
||||
import { robotsResponse } from "@server/utils/robots";
|
||||
@@ -118,22 +116,6 @@ router.get("/opensearch.xml", (ctx) => {
|
||||
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/doc/:documentSlug", renderShare);
|
||||
router.get("/s/:shareId/*", renderShare);
|
||||
|
||||
Reference in New Issue
Block a user