mc-dashboard/app/api/logs/route.ts
hurkicorgi dd69c17c3b Initial commit: Minecraft dashboard
Next.js 16 + Tailwind v4 + shadcn v4 dashboard for managing a modded
Forge 1.20.1 server. Includes server controls, player management, mod
manager with Modrinth search and dependency resolution, world backups,
snapshots, analytics, logs, and chat bridge.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 00:46:58 -06:00

30 lines
765 B
TypeScript

import { NextRequest, NextResponse } from "next/server";
import { execSync } from "child_process";
import { auth } from "@/lib/auth";
export const dynamic = "force-dynamic";
export async function GET(req: NextRequest) {
const session = await auth();
if (!session) {
return NextResponse.json({ error: "Unauthorized" }, { status: 403 });
}
const lines = Math.min(
parseInt(req.nextUrl.searchParams.get("lines") || "50"),
200
);
try {
const logs = execSync(
`sudo journalctl -u minecraft.service --no-pager -n ${lines}`,
{ encoding: "utf8", timeout: 5000 }
);
return NextResponse.json({ logs });
} catch (e) {
return NextResponse.json(
{ error: (e as Error).message },
{ status: 500 }
);
}
}