import { NextResponse } from "next/server"; import { readFile } from "node:fs/promises"; import { safeJoinSitePath } from "@/lib/config"; import { analyzeLogs } from "@/lib/analyzeLogs"; export const runtime = "nodejs"; export async function GET( _req: Request, ctx: { params: Promise<{ dir: string }> } ) { try { const { dir } = await ctx.params; const filePath = safeJoinSitePath(dir, "log", "access.log"); const content = await readFile(filePath, { encoding: "utf-8" }); const data = await analyzeLogs(content); return NextResponse.json(data); } catch (error) { return NextResponse.json({ error: String(error) }, { status: 404 }); } }