diff --git a/apps/web/nginx.conf b/apps/web/nginx.conf index f896173..6c1ed09 100644 --- a/apps/web/nginx.conf +++ b/apps/web/nginx.conf @@ -14,6 +14,20 @@ server { proxy_set_header X-Forwarded-Proto $scheme; } + location = /sw.js { + add_header Cache-Control "no-cache"; + try_files $uri =404; + } + + location = /index.html { + add_header Cache-Control "no-cache"; + try_files $uri =404; + } + + location ~* ^/assets/.*\.(?:js|css)$ { + try_files $uri =404; + } + location / { try_files $uri $uri/ /index.html; } diff --git a/apps/web/vite.config.ts b/apps/web/vite.config.ts index fc2b629..439949c 100644 --- a/apps/web/vite.config.ts +++ b/apps/web/vite.config.ts @@ -99,7 +99,7 @@ function offlineServiceWorkerPlugin(): Plugin { const bundledAssets = Object.keys(bundle) .filter((fileName) => fileName !== "sw.js") .map((fileName) => `/${fileName}`); - const precache = [...new Set([...bundledAssets, ...publicAssets])]; + const precache = [...new Set(["/", ...bundledAssets, ...publicAssets])]; const source = `const CACHE_NAME = "cents-shell-v4"; const PRECACHE = ${JSON.stringify(precache, null, 2)}; @@ -126,7 +126,7 @@ self.addEventListener("fetch", (event) => { const copy = response.clone(); void caches.open(CACHE_NAME).then((cache) => cache.put("/", copy)); return response; - }).catch(() => caches.match("/")), + }).catch(async () => (await caches.match("/")) ?? caches.match("/index.html")), ); return; }