Files
cloudflare-domain-manager/apps/api/src/routes/health.ts
T
Denozordec 1d497d01c2
Build and Push CFDM Docker Image / build-and-push (push) Successful in 1m59s
Build and Push CFDM Docker Image / create-release (push) Skipped
Build and Push CFDM Docker Image / update-wiki (push) Successful in 7s
feat(health-check): add TLS verification option to health check configuration
Introduced a new `verify_tls` boolean option in health check configurations across various services, allowing users to specify whether to validate TLS certificates during health checks. Updated related components and services to accommodate this new option, ensuring proper handling in both the backend and frontend. Enhanced tests to validate the new functionality and ensure correct behavior with different configurations.
2026-07-20 17:28:02 +07:00

65 lines
1.7 KiB
TypeScript

import type { FastifyInstance } from "fastify";
import { z } from "zod";
import { healthCheck } from "../plugins/db.js";
import * as authService from "../services/auth.js";
export async function healthRoutes(app: FastifyInstance) {
app.get("/health", async (request, reply) => {
healthCheck(request.server.sqlite);
return { status: "ok" };
});
app.get("/ready", async (request, reply) => {
healthCheck(request.server.sqlite);
let cloudflare = false;
if (request.server.config.cloudflareApiToken) {
try {
await request.server.cf.listZones();
cloudflare = true;
} catch {
cloudflare = false;
}
}
return {
status: cloudflare || !request.server.config.cloudflareApiToken
? "ready"
: "degraded",
database: true,
cloudflare,
};
});
}
export async function authRoutes(app: FastifyInstance) {
app.get("/auth/config", async (request) => {
const { config } = request.server;
return {
required: config.authRequired,
portal_url: config.authPortalUrl,
};
});
const loginSchema = z.object({
username: z.string(),
password: z.string(),
});
app.post("/auth/login", async (request, reply) => {
if (request.server.config.authRequired) {
return reply.code(403).send({
error: {
code: "FORBIDDEN",
message: "Локальный вход отключён — используйте auth-portal",
},
});
}
const body = loginSchema.parse(request.body);
const result = await authService.login(
request.server.config,
(payload) => request.server.jwt.sign(payload),
body,
);
return result;
});
}