9d32552457
Replace Vercel-specific infra (Cron, Blob) with self-hosted equivalents for deployment to Coolify: in-container cron scheduler (scripts/cron-runner.mjs) and disk-based upload storage served via /api/uploads/[...path]. Add Dockerfile, .dockerignore, and /api/health for container health checks. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
48 lines
1.5 KiB
JavaScript
48 lines
1.5 KiB
JavaScript
// Service worker: installable app shell + offline fallback.
|
|
// Never caches API responses or page HTML — they carry per-user, per-page data.
|
|
const VERSION = "pm-v4";
|
|
const STATIC_CACHE = `${VERSION}-static`;
|
|
const OFFLINE_URL = "/offline.html";
|
|
|
|
self.addEventListener("install", (event) => {
|
|
event.waitUntil(caches.open(STATIC_CACHE).then((c) => c.addAll([OFFLINE_URL, "/icons/192"])));
|
|
self.skipWaiting();
|
|
});
|
|
|
|
self.addEventListener("activate", (event) => {
|
|
event.waitUntil(
|
|
caches.keys().then((keys) => Promise.all(keys.filter((k) => !k.startsWith(VERSION)).map((k) => caches.delete(k))))
|
|
);
|
|
self.clients.claim();
|
|
});
|
|
|
|
self.addEventListener("fetch", (event) => {
|
|
const req = event.request;
|
|
if (req.method !== "GET") return;
|
|
const url = new URL(req.url);
|
|
if (url.origin !== self.location.origin) return;
|
|
|
|
// Page navigations: network only, offline page when the network is gone.
|
|
if (req.mode === "navigate") {
|
|
event.respondWith(fetch(req).catch(() => caches.match(OFFLINE_URL)));
|
|
return;
|
|
}
|
|
|
|
// Build assets are content-hashed: cache-first is safe.
|
|
if (url.pathname.startsWith("/_next/static/") || url.pathname.startsWith("/icons/")) {
|
|
event.respondWith(
|
|
caches.match(req).then(
|
|
(hit) =>
|
|
hit ||
|
|
fetch(req).then((res) => {
|
|
if (res.ok) {
|
|
const copy = res.clone();
|
|
caches.open(STATIC_CACHE).then((c) => c.put(req, copy));
|
|
}
|
|
return res;
|
|
})
|
|
)
|
|
);
|
|
}
|
|
});
|