Files
forex-dashboard/app/api/news/route.ts
T
caty21 886a5b426f fix: force-dynamic on all API routes + PWA manifest & service worker
- Add export const dynamic = "force-dynamic" to routes previously
  pre-rendered as static (rate-probabilities, news, fx, yields, calendar)
  → fixes empty data on Vercel where static pre-render got HTTP 403
- Add PWA: manifest.json, sw.js, icons, layout meta + apple-touch-icon

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-27 15:19:35 +02:00

25 lines
784 B
TypeScript

import { NextResponse } from "next/server";
import { fetchAllNews } from "@/lib/newsfeed";
import type { NewsItem } from "@/lib/newsfeed";
export const dynamic = "force-dynamic";
export type { NewsItem } from "@/lib/newsfeed";
let _cache: { data: NewsItem[]; ts: number } | null = null;
const TTL = 5 * 60_000; // 5 min — actualités fraîches
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() },
{ headers: { "Cache-Control": "s-maxage=300, stale-while-revalidate=600" } }
);
}