One Calendar is a privacy-first calendar web app built with Next.js. It has modern security features, including e2ee, password-protected sharing, and self-destructing share links ๐Ÿ“… calendar.xyehr.cn
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #226 from EvanTechDev/feature/fix-schedule-data-caching-issue

fix: prevent service worker from serving stale /api backup data

authored by

Evan Huang and committed by
GitHub
7ac7981b faebf24c

+24 -2
+3 -1
proxy.ts
··· 12 12 "/api/atproto/(.*)", 13 13 "/oauth-client-metadata.json", 14 14 "/api/share/public", 15 + "/privacy", 16 + "/terms", 15 17 ]) 16 18 17 19 export default clerkMiddleware(async (auth, req) => { 18 20 if (!isPublicRoute(req)) { 19 - await auth.protect() 21 + await auth.protect({ unauthenticatedUrl: "/sign-in" }) 20 22 } 21 23 }) 22 24
+21 -1
public/sw.js
··· 1 - const CACHE_NAME = "one-calendar-shell-v1"; 1 + const CACHE_NAME = "one-calendar-shell-v3"; 2 2 const OFFLINE_URLS = ["/app", "/icon.svg"]; 3 + const STATIC_PATH_PREFIXES = ["/_next/static/", "/_next/image/", "/icons/"]; 4 + const STATIC_FILE_PATTERN = 5 + /\.(?:js|css|png|jpg|jpeg|gif|svg|webp|ico|woff|woff2|ttf|otf|eot|json|txt|xml|webmanifest)$/i; 6 + 7 + function shouldCacheRequest(requestUrl) { 8 + if (requestUrl.origin !== self.location.origin) return false; 9 + if (OFFLINE_URLS.includes(requestUrl.pathname)) return true; 10 + if (STATIC_PATH_PREFIXES.some((prefix) => requestUrl.pathname.startsWith(prefix))) { 11 + return true; 12 + } 13 + return STATIC_FILE_PATTERN.test(requestUrl.pathname); 14 + } 3 15 4 16 self.addEventListener("install", (event) => { 5 17 event.waitUntil( ··· 29 41 30 42 const requestUrl = new URL(event.request.url); 31 43 if (requestUrl.protocol !== "http:" && requestUrl.protocol !== "https:") { 44 + return; 45 + } 46 + if (requestUrl.pathname.startsWith("/api/")) { 47 + event.respondWith(fetch(event.request)); 48 + return; 49 + } 50 + if (!shouldCacheRequest(requestUrl)) { 51 + event.respondWith(fetch(event.request)); 32 52 return; 33 53 } 34 54