summary refs log tree commit diff
path: root/src/api/Server.ts
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2026-01-22 19:42:24 +0100
committerRory& <root@rory.gay>2026-01-22 19:42:24 +0100
commit935f7960a676a11d60d4a5e3990c1920d747790e (patch)
tree3ac329aa7a365220657ec32b5058ed0d19d2fa2b /src/api/Server.ts
parentApply-migrations: retry (diff)
downloadserver-ts-935f7960a676a11d60d4a5e3990c1920d747790e.tar.xz
Move health endpoints to /, deprecate /api/-. Fixes #1089
Diffstat (limited to 'src/api/Server.ts')
-rw-r--r--src/api/Server.ts11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/api/Server.ts b/src/api/Server.ts

index 5fab5e5b..bac34d61 100644 --- a/src/api/Server.ts +++ b/src/api/Server.ts
@@ -16,7 +16,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ -import { Config, ConnectionConfig, ConnectionLoader, Email, JSONReplacer, WebAuthn, initDatabase, initEvent, registerRoutes } from "@spacebar/util"; +import { Config, ConnectionConfig, ConnectionLoader, Email, JSONReplacer, WebAuthn, initDatabase, initEvent, registerRoutes, getDatabase } from "@spacebar/util"; import { Authentication, CORS, ImageProxy, BodyParser, ErrorHandler, initRateLimits, initTranslation } from "./middlewares"; import { Request, Response, Router } from "express"; import { Server, ServerOptions } from "lambert-server"; @@ -24,6 +24,7 @@ import morgan from "morgan"; import path from "path"; import { red } from "picocolors"; import { initInstance } from "./util/handlers/Instance"; +import { route } from "./util"; const ASSETS_FOLDER = path.join(__dirname, "..", "..", "assets"); const PUBLIC_ASSETS_FOLDER = path.join(ASSETS_FOLDER, "public"); @@ -182,6 +183,14 @@ export class SpacebarServer extends Server { }); }); + function isReady(req: Request, res: Response) { + if (!getDatabase()) return res.sendStatus(503); + return res.sendStatus(200); + } + + app.get("/readyz", route({ description: "Get the ready state of the server" }), isReady); + app.get("/healthz", route({ description: "Get the ready state of the server" }), isReady); + this.app.use(ErrorHandler); ConnectionLoader.loadConnections();