init
This commit is contained in:
44
app/api/matches/route.ts
Normal file
44
app/api/matches/route.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { fetchMatchesAndTeams, fetchOdds, attachOdds } from "@/lib/feeds";
|
||||
import { computeGroupTables, computeThirdPlaceTable } from "@/lib/standings";
|
||||
import { qualifiedThirdGroups, resolveAnnexC } from "@/lib/bracket";
|
||||
|
||||
// Diese Route wird vom Frontend gepollt. Sie ist der einzige Ort, der die
|
||||
// Upstream-Feeds berührt — gecacht, damit Rate Limits eingehalten werden.
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const { matches: rawMatches, teams } = await fetchMatchesAndTeams();
|
||||
|
||||
// Odds sind optional: fällt der Polymarket-Call aus, liefern wir trotzdem.
|
||||
let matches = rawMatches;
|
||||
try {
|
||||
const odds = await fetchOdds();
|
||||
matches = attachOdds(rawMatches, teams, odds);
|
||||
} catch {
|
||||
// still ohne Wahrscheinlichkeiten
|
||||
}
|
||||
|
||||
const groupTables = computeGroupTables(teams, matches);
|
||||
const thirdTable = computeThirdPlaceTable(groupTables);
|
||||
const qGroups = qualifiedThirdGroups(thirdTable);
|
||||
const annex = qGroups.length === 8 ? resolveAnnexC(qGroups) : null;
|
||||
|
||||
return NextResponse.json({
|
||||
updatedAt: new Date().toISOString(),
|
||||
teams,
|
||||
matches,
|
||||
groupTables,
|
||||
thirdTable,
|
||||
annexAssignment: annex,
|
||||
annexResolved: annex != null,
|
||||
});
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : "unbekannter Fehler";
|
||||
return NextResponse.json(
|
||||
{ error: "Feed nicht erreichbar", detail: message },
|
||||
{ status: 502 },
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user