Files
web/apps/redis-api/src/routes/health.ts
T
Anton Gunnarsson dd4ef527df Merged in chore/eslint9 (pull request #2029)
chore: Update to ESLint 9

* wip: apply codemod and upgrade swc plugin

* Update eslint to 9 in scandic-web

apply code mod to config
fix existing lint issues

* Remove uneccessary fixupConfigRules

* Update eslint to 9 in design-system

* Add lint turbo dependency

* Move redis-api to eslint and prettier instead of biome

* Simplify eslint configs

* Clean up

* Apply linting


Approved-by: Linus Flood
2025-06-03 14:26:44 +00:00

57 lines
1.4 KiB
TypeScript

import Elysia, { t } from "elysia";
import { env } from "@/env";
import { redis } from "@/services/redis";
import { baseLogger } from "@/utils/logger";
const healthLogger = baseLogger.child({
module: "health",
});
export const healthRoutes = new Elysia().get(
"/health",
async ({ status }) => {
const perf = performance.now();
let healthy = true;
try {
await redis.ping();
} catch (e) {
healthLogger.error("Redis connection error:", e);
healthy = false;
}
const duration = performance.now() - perf;
const durationString = `${duration.toFixed(2)} ms`;
if (!healthy) {
healthLogger.error("Health check failed");
return status(503, {
healthy,
version: env.VERSION,
duration: durationString,
});
}
return {
healthy,
version: env.VERSION,
duration: durationString,
};
},
{
response: {
200: t.Object({
healthy: t.Boolean(),
version: t.String(),
duration: t.String(),
}),
503: t.Object({
healthy: t.Boolean(),
version: t.String(),
duration: t.String(),
}),
},
},
);