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>
32 lines
908 B
TypeScript
32 lines
908 B
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { exec } from "child_process";
|
|
import { auth } from "@/lib/auth";
|
|
|
|
const ALLOWED_ACTIONS = ["start", "stop", "restart"];
|
|
|
|
export async function POST(
|
|
_req: NextRequest,
|
|
{ params }: { params: Promise<{ action: string }> }
|
|
) {
|
|
const session = await auth();
|
|
if (!session) {
|
|
return NextResponse.json({ error: "Unauthorized" }, { status: 403 });
|
|
}
|
|
|
|
const { action } = await params;
|
|
if (!ALLOWED_ACTIONS.includes(action)) {
|
|
return NextResponse.json({ error: "Invalid action" }, { status: 400 });
|
|
}
|
|
|
|
return new Promise<NextResponse>((resolve) => {
|
|
exec(`sudo systemctl ${action} minecraft.service`, (err) => {
|
|
if (err) {
|
|
resolve(
|
|
NextResponse.json({ error: err.message }, { status: 500 })
|
|
);
|
|
} else {
|
|
resolve(NextResponse.json({ ok: true, action }));
|
|
}
|
|
});
|
|
});
|
|
}
|