Files
forex-dashboard/public/sw.js
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

37 lines
1.1 KiB
JavaScript

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;
})
);
});