mc-dashboard/app/api/players/stats/route.ts

29 lines
747 B
TypeScript
Raw Normal View History

import { NextResponse } from "next/server";
import { auth } from "@/lib/auth";
import { memoAsync } from "@/lib/cache";
import { computePlayerStats } from "@/lib/player-stats";
export const dynamic = "force-dynamic";
export const runtime = "nodejs";
export async function GET() {
const session = await auth();
if (!session) {
return NextResponse.json({ error: "Unauthorized" }, { status: 403 });
}
try {
const data = await memoAsync("players:stats", 60_000, async () =>
computePlayerStats()
);
return NextResponse.json(data, {
headers: { "Cache-Control": "private, max-age=60" },
});
} catch (e) {
return NextResponse.json(
{ error: (e as Error).message },
{ status: 500 }
);
}
}