diff --git a/public/sw.js b/public/sw.js index 0c4e244..06bbaec 100644 --- a/public/sw.js +++ b/public/sw.js @@ -1,4 +1,4 @@ -const CACHE_NAME = 'puffin-calculator-v1'; +const CACHE_NAME = 'puffin-calculator-v2'; // Bumped to clear old cached code const urlsToCache = [ '/', '/mobile-app', @@ -21,6 +21,22 @@ self.addEventListener('install', (event) => { ); }); +// Activate event - clear old caches +self.addEventListener('activate', (event) => { + event.waitUntil( + caches.keys().then((cacheNames) => { + return Promise.all( + cacheNames.map((cacheName) => { + if (cacheName !== CACHE_NAME) { + console.log('Clearing old cache:', cacheName); + return caches.delete(cacheName); + } + }) + ); + }) + ); +}); + // Fetch event - serve from cache when offline self.addEventListener('fetch', (event) => { event.respondWith( diff --git a/src/api/checkoutClient.ts b/src/api/checkoutClient.ts index 2785187..f85c6fd 100644 --- a/src/api/checkoutClient.ts +++ b/src/api/checkoutClient.ts @@ -10,8 +10,8 @@ const getApiBaseUrl = (): string => { return window.env.API_BASE_URL; } - // Fall back to build-time env or default - return import.meta.env.VITE_API_BASE_URL || 'http://localhost:3001'; + // Fall back to build-time env or production default + return import.meta.env.VITE_API_BASE_URL || 'https://puffinoffset.com/api'; }; export interface CreateCheckoutSessionParams { diff --git a/src/main.tsx b/src/main.tsx index 360a4ae..9eff9d6 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -9,10 +9,18 @@ if ('serviceWorker' in navigator) { window.addEventListener('load', () => { navigator.serviceWorker.register('/sw.js') .then((registration) => { - console.log('SW registered: ', registration); + console.log('✅ Service Worker registered:', registration); + + // Check for updates immediately + registration.update(); + + // Log when a new service worker is waiting + if (registration.waiting) { + console.log('⚠️ New service worker waiting. Reload page to activate.'); + } }) .catch((registrationError) => { - console.log('SW registration failed: ', registrationError); + console.error('❌ SW registration failed:', registrationError); }); }); }