first commit
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
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 });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { safeJoinSitePath } from "@/lib/config";
|
||||
|
||||
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" });
|
||||
return new NextResponse(content, { headers: { "content-type": "text/plain; charset=utf-8" } });
|
||||
} catch (error) {
|
||||
return NextResponse.json({ error: String(error) }, { status: 404 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user