2026-06-03 00:59:04 +02:00
|
|
|
import { NextResponse } from "next/server";
|
|
|
|
|
import { fetchAllNews } from "@/lib/newsfeed";
|
|
|
|
|
import type { NewsItem } from "@/lib/newsfeed";
|
|
|
|
|
|
2026-06-27 15:19:35 +02:00
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
|
|
2026-06-03 00:59:04 +02:00
|
|
|
export type { NewsItem } from "@/lib/newsfeed";
|
|
|
|
|
|
|
|
|
|
let _cache: { data: NewsItem[]; ts: number } | null = null;
|
2026-06-08 14:33:23 +02:00
|
|
|
const TTL = 5 * 60_000; // 5 min — actualités fraîches
|
2026-06-03 00:59:04 +02:00
|
|
|
|
|
|
|
|
export async function GET() {
|
|
|
|
|
if (_cache && Date.now() - _cache.ts < TTL) {
|
|
|
|
|
return NextResponse.json({ items: _cache.data, fetchedAt: new Date(_cache.ts).toISOString() });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const items = await fetchAllNews();
|
|
|
|
|
_cache = { data: items, ts: Date.now() };
|
|
|
|
|
|
|
|
|
|
return NextResponse.json(
|
|
|
|
|
{ items, fetchedAt: new Date().toISOString() },
|
2026-06-08 14:33:23 +02:00
|
|
|
{ headers: { "Cache-Control": "s-maxage=300, stale-while-revalidate=600" } }
|
2026-06-03 00:59:04 +02:00
|
|
|
);
|
|
|
|
|
}
|