2026-06-01 23:24:32 +02:00
|
|
|
import { NextResponse } from "next/server";
|
|
|
|
|
import { fetchAllCBPaths } from "@/lib/rateprobability";
|
|
|
|
|
import type { RateProbData } from "@/lib/rateprobability";
|
|
|
|
|
|
2026-06-27 15:19:35 +02:00
|
|
|
export const dynamic = "force-dynamic";
|
2026-06-27 16:27:20 +02:00
|
|
|
export const preferredRegion = ["fra1", "lhr1", "cdg1"]; // Europe (Frankfurt / London / Paris)
|
2026-06-27 15:19:35 +02:00
|
|
|
|
2026-06-01 23:24:32 +02:00
|
|
|
export type { RateProbData, CBRatePath, RateProbMeeting } from "@/lib/rateprobability";
|
|
|
|
|
|
|
|
|
|
export interface RateProbabilitiesResponse {
|
|
|
|
|
data: RateProbData;
|
|
|
|
|
fetchedAt: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function GET() {
|
2026-07-14 23:05:37 +02:00
|
|
|
try {
|
|
|
|
|
const data = await fetchAllCBPaths();
|
|
|
|
|
const currencies = Object.keys(data);
|
|
|
|
|
console.log(`[rate-prob] fetched ${currencies.length} CBs: ${currencies.join(", ")}`);
|
|
|
|
|
return NextResponse.json(
|
|
|
|
|
{ data, fetchedAt: new Date().toISOString() } satisfies RateProbabilitiesResponse,
|
|
|
|
|
{ headers: { "Cache-Control": "no-store" } }
|
|
|
|
|
);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
// Ne jamais laisser une exception (ex: timeout InvestingLive) faire planter la route
|
|
|
|
|
// entière — ça faisait échouer le fetch() client pour les 8 devises d'un coup au lieu
|
|
|
|
|
// de dégrader currency par currency. On renvoie un JSON valide (vide) : le client bascule
|
|
|
|
|
// sur son cache localStorage plutôt que de rester bloqué sur "Données OIS indisponibles".
|
|
|
|
|
console.error(`[rate-prob] fatal error: ${e instanceof Error ? e.message : e}`);
|
|
|
|
|
return NextResponse.json(
|
|
|
|
|
{ data: {}, fetchedAt: new Date().toISOString() } satisfies RateProbabilitiesResponse,
|
|
|
|
|
{ headers: { "Cache-Control": "no-store" } }
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-06-01 23:24:32 +02:00
|
|
|
}
|