mirror of
https://github.com/caty21/forex-dashboard.git
synced 2026-07-27 20:37:45 +00:00
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>
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import rateDecisionsData from "@/data/rate_decisions.json";
|
||||
import { fetchFFEvents, nextWeekAvailable } from "@/lib/forexfactory";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
import type { FFEvent } from "@/lib/forexfactory";
|
||||
import type { Currency } from "@/lib/types";
|
||||
import { fetchAllCBPaths, extractMeetingEvents } from "@/lib/rateprobability";
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
const CURRENCIES = ["EUR", "GBP", "JPY", "CHF", "CAD", "AUD", "NZD", "SEK"];
|
||||
const AV_BASE = "https://www.alphavantage.co/query";
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ 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;
|
||||
|
||||
@@ -2,6 +2,8 @@ import { NextResponse } from "next/server";
|
||||
import { fetchAllCBPaths } from "@/lib/rateprobability";
|
||||
import type { RateProbData } from "@/lib/rateprobability";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export type { RateProbData, CBRatePath, RateProbMeeting } from "@/lib/rateprobability";
|
||||
|
||||
export interface RateProbabilitiesResponse {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { fetchTEBondYields } from "@/lib/tebonds";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
// Variation % d'un pair FX vs clôture J-1 (Yahoo Finance, cache 5 min)
|
||||
// Valeur positive = devise X plus forte vs USD (ou USD plus fort si pair inversé)
|
||||
async function fxChangePct(symbol: string, invert = false): Promise<number | null> {
|
||||
|
||||
+23
-2
@@ -1,15 +1,36 @@
|
||||
import type { Metadata } from "next";
|
||||
import type { Metadata, Viewport } from "next";
|
||||
import "./globals.css";
|
||||
import Script from "next/script";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Forex Macro Dashboard",
|
||||
description: "Tableau de bord macroéconomique Forex — 8 devises majeures",
|
||||
manifest: "/manifest.json",
|
||||
appleWebApp: {
|
||||
capable: true,
|
||||
statusBarStyle: "black-translucent",
|
||||
title: "FX Dashboard",
|
||||
},
|
||||
};
|
||||
|
||||
export const viewport: Viewport = {
|
||||
themeColor: "#090e1a",
|
||||
};
|
||||
|
||||
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
<html lang="fr">
|
||||
<body className="min-h-screen bg-[#090e1a]">{children}</body>
|
||||
<head>
|
||||
<link rel="apple-touch-icon" href="/icons/icon-192.svg" />
|
||||
</head>
|
||||
<body className="min-h-screen bg-[#090e1a]">
|
||||
{children}
|
||||
<Script id="sw-register" strategy="afterInteractive">
|
||||
{`if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.register('/sw.js').catch(() => {});
|
||||
}`}
|
||||
</Script>
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="192" height="192" viewBox="0 0 192 192">
|
||||
<rect width="192" height="192" rx="34" fill="#090e1a"/>
|
||||
<text x="50%" y="54%" font-family="Arial,sans-serif" font-weight="bold" font-size="80" fill="#f59e0b" text-anchor="middle" dominant-baseline="middle">FX</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 315 B |
@@ -0,0 +1,4 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="512" height="512" viewBox="0 0 512 512">
|
||||
<rect width="512" height="512" rx="92" fill="#090e1a"/>
|
||||
<text x="50%" y="54%" font-family="Arial,sans-serif" font-weight="bold" font-size="215" fill="#f59e0b" text-anchor="middle" dominant-baseline="middle">FX</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 316 B |
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "Forex Macro Dashboard",
|
||||
"short_name": "FX Dashboard",
|
||||
"description": "Tableau de bord macroéconomique Forex — 8 devises majeures",
|
||||
"start_url": "/",
|
||||
"display": "standalone",
|
||||
"background_color": "#090e1a",
|
||||
"theme_color": "#090e1a",
|
||||
"orientation": "portrait-primary",
|
||||
"icons": [
|
||||
{
|
||||
"src": "/icons/icon-192.svg",
|
||||
"sizes": "192x192",
|
||||
"type": "image/svg+xml",
|
||||
"purpose": "any maskable"
|
||||
},
|
||||
{
|
||||
"src": "/icons/icon-512.svg",
|
||||
"sizes": "512x512",
|
||||
"type": "image/svg+xml",
|
||||
"purpose": "any maskable"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
const CACHE = "fxdash-v1";
|
||||
const STATIC = ["/", "/manifest.json", "/icons/icon-192.svg", "/icons/icon-512.svg"];
|
||||
|
||||
self.addEventListener("install", (e) => {
|
||||
e.waitUntil(caches.open(CACHE).then((c) => c.addAll(STATIC)));
|
||||
self.skipWaiting();
|
||||
});
|
||||
|
||||
self.addEventListener("activate", (e) => {
|
||||
e.waitUntil(
|
||||
caches.keys().then((keys) =>
|
||||
Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k)))
|
||||
)
|
||||
);
|
||||
self.clients.claim();
|
||||
});
|
||||
|
||||
self.addEventListener("fetch", (e) => {
|
||||
// Only cache GET requests for same-origin static assets; pass API calls through
|
||||
const url = new URL(e.request.url);
|
||||
if (e.request.method !== "GET") return;
|
||||
if (url.pathname.startsWith("/api/")) return; // always fresh for API
|
||||
|
||||
e.respondWith(
|
||||
caches.match(e.request).then((cached) => {
|
||||
const network = fetch(e.request).then((res) => {
|
||||
if (res.ok && res.type === "basic") {
|
||||
const clone = res.clone();
|
||||
caches.open(CACHE).then((c) => c.put(e.request, clone));
|
||||
}
|
||||
return res;
|
||||
});
|
||||
return cached || network;
|
||||
})
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user