- docker-compose: itzg/minecraft-server (Fabric, offline mode, whitelist enforced, Modrinth-managed mods), itzg/mc-backup sidecar, custom dashboard - Gated auth for offline mode: approve username -> whitelisted with a short registration window -> EasyAuth /register + /login; auto-revoke on expiry - CraftDeck panel (Next.js 16, zero native deps): live console (SSE), players & stats, lag diagnostics (server TPS vs player ping via spark), performance graphs, Modrinth mod search/manager, backups & restore, sandboxed file browser/editor, .env config editor with compose apply, cron schedules, Discord alerts, scrypt-hashed panel login - scripts/setup.sh generates secrets; docs/ covers auth, mods, updating, backups, networking (Tailscale), troubleshooting Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
import { NextRequest } from "next/server";
|
|
import { bus, logRing } from "@/server/bus";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
/** Live console stream (SSE). Backfills recent lines, then follows. */
|
|
export async function GET(req: NextRequest) {
|
|
const encoder = new TextEncoder();
|
|
let closed = false;
|
|
|
|
const stream = new ReadableStream({
|
|
start(controller) {
|
|
const send = (line: string) => {
|
|
if (closed) return;
|
|
try {
|
|
controller.enqueue(encoder.encode(`data: ${JSON.stringify(line)}\n\n`));
|
|
} catch {
|
|
closed = true;
|
|
}
|
|
};
|
|
for (const line of logRing()) send(line);
|
|
const onLog = (line: string) => send(line);
|
|
bus().on("log", onLog);
|
|
const keepalive = setInterval(() => {
|
|
if (closed) return;
|
|
try {
|
|
controller.enqueue(encoder.encode(": keepalive\n\n"));
|
|
} catch {
|
|
closed = true;
|
|
}
|
|
}, 15000);
|
|
req.signal.addEventListener("abort", () => {
|
|
closed = true;
|
|
bus().off("log", onLog);
|
|
clearInterval(keepalive);
|
|
try {
|
|
controller.close();
|
|
} catch {}
|
|
});
|
|
},
|
|
});
|
|
|
|
return new Response(stream, {
|
|
headers: {
|
|
"Content-Type": "text/event-stream",
|
|
"Cache-Control": "no-cache, no-transform",
|
|
Connection: "keep-alive",
|
|
"X-Accel-Buffering": "no",
|
|
},
|
|
});
|
|
}
|