| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- import { NextResponse } from "next/server";
- import { getDb } from "@/lib/db";
- import fs from "fs/promises";
- /**
- * GET /api/health
- *
- * Health check endpoint:
- * - Verifies database connectivity.
- * - Verifies readability of NAS_ROOT_PATH.
- */
- export async function GET() {
- const result = {
- db: null,
- nas: null,
- };
- // --- Database health -------------------------------------------------------
- try {
- const db = await getDb();
- await db.command({ ping: 1 });
- result.db = "ok";
- } catch (error) {
- // We don't throw here – we report the error in the JSON result
- result.db = `error: ${error.message}`;
- }
- // --- NAS health ------------------------------------------------------------
- const nasPath = process.env.NAS_ROOT_PATH || "/mnt/niederlassungen";
- try {
- const entries = await fs.readdir(nasPath);
- result.nas = {
- path: nasPath,
- entriesSample: entries.slice(0, 5),
- };
- } catch (error) {
- // It's okay if NAS is not available in some environments (like local dev),
- // we just propagate the error message in the health object.
- result.nas = `error: ${error.message}`;
- }
- return NextResponse.json(result);
- }
|