- 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>
60 lines
1.7 KiB
TypeScript
60 lines
1.7 KiB
TypeScript
import { NextRequest } from "next/server";
|
|
import { bus } from "@/server/bus";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
/**
|
|
* Multiplexed live event stream (SSE) for the UI: sampler metrics ticks,
|
|
* parsed game events, and new notifications.
|
|
*/
|
|
export async function GET(req: NextRequest) {
|
|
const encoder = new TextEncoder();
|
|
let closed = false;
|
|
|
|
const stream = new ReadableStream({
|
|
start(controller) {
|
|
const send = (event: string, data: unknown) => {
|
|
if (closed) return;
|
|
try {
|
|
controller.enqueue(encoder.encode(`event: ${event}\ndata: ${JSON.stringify(data)}\n\n`));
|
|
} catch {
|
|
closed = true;
|
|
}
|
|
};
|
|
const onMetrics = (m: unknown) => send("metrics", m);
|
|
const onEvent = (e: unknown) => send("mc-event", e);
|
|
const onNotification = (n: unknown) => send("notification", n);
|
|
bus().on("metrics", onMetrics);
|
|
bus().on("mc-event", onEvent);
|
|
bus().on("notification", onNotification);
|
|
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("metrics", onMetrics);
|
|
bus().off("mc-event", onEvent);
|
|
bus().off("notification", onNotification);
|
|
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",
|
|
},
|
|
});
|
|
}
|