From 1135821195dd8e29e21549bf726eff4e07c4c802 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 20 Jul 2025 15:34:01 -0500 Subject: [PATCH] Remove ServiceWorker --- public/sw.js | 86 ---------------------------------------------------- src/main.tsx | 12 -------- 2 files changed, 98 deletions(-) delete mode 100644 public/sw.js diff --git a/public/sw.js b/public/sw.js deleted file mode 100644 index 2d2b34cf..00000000 --- a/public/sw.js +++ /dev/null @@ -1,86 +0,0 @@ -// Service Worker for serving files from LightningFS filesystem -// Import LightningFS using importScripts (ServiceWorker compatible) -importScripts('https://unpkg.com/@isomorphic-git/lightning-fs@4.6.2/dist/lightning-fs.min.js'); - -// Initialize LightningFS in the service worker -const fs = new LightningFS('shakespeare-fs'); -const projectsDir = '/projects'; - -// Handle file requests from the virtual filesystem -async function handleFileRequest(url) { - const urlObj = new URL(url); - const pathMatch = urlObj.pathname.match(/^\/project\/([^\/]+)\/files\/(.+)$/); - - if (!pathMatch) { - return new Response('Not Found', { status: 404 }); - } - - const [, projectId, filePath] = pathMatch; - - try { - // Read file directly from LightningFS - const fullPath = `${projectsDir}/${projectId}/${filePath}`; - const fileContent = await fs.promises.readFile(fullPath, 'utf8'); - - // Determine content type based on file extension - const contentType = getContentType(filePath); - - return new Response(fileContent, { - status: 200, - headers: { - 'Content-Type': contentType, - 'Cache-Control': 'no-cache', // Don't cache for development - }, - }); - } catch (error) { - console.error('Failed to read file:', error); - return new Response('File Not Found', { status: 404 }); - } -} - -// Get content type based on file extension -function getContentType(filePath) { - const ext = filePath.split('.').pop()?.toLowerCase(); - - const mimeTypes = { - 'html': 'text/html', - 'css': 'text/css', - 'js': 'application/javascript', - 'jsx': 'application/javascript', - 'ts': 'application/javascript', - 'tsx': 'application/javascript', - 'json': 'application/json', - 'png': 'image/png', - 'jpg': 'image/jpeg', - 'jpeg': 'image/jpeg', - 'gif': 'image/gif', - 'svg': 'image/svg+xml', - 'ico': 'image/x-icon', - 'woff': 'font/woff', - 'woff2': 'font/woff2', - 'ttf': 'font/ttf', - 'eot': 'application/vnd.ms-fontobject', - }; - - return mimeTypes[ext] || 'text/plain'; -} - -// Service Worker event listeners -self.addEventListener('install', (event) => { - console.log('Service Worker installing...'); - self.skipWaiting(); -}); - -self.addEventListener('activate', (event) => { - console.log('Service Worker activating...'); - event.waitUntil(self.clients.claim()); -}); - -self.addEventListener('fetch', (event) => { - const url = event.request.url; - - // Only handle requests for project files - if (url.includes('/project/') && url.includes('/files/')) { - event.respondWith(handleFileRequest(url)); - } -}); \ No newline at end of file diff --git a/src/main.tsx b/src/main.tsx index cd9c3424..5dfd85d9 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -9,16 +9,4 @@ import './index.css'; // Using Inter Variable font for modern, clean typography import '@fontsource-variable/inter'; -// Register service worker for file serving -if ('serviceWorker' in navigator) { - window.addEventListener('load', async () => { - try { - const registration = await navigator.serviceWorker.register('/sw.js'); - console.log('SW registered: ', registration); - } catch (registrationError) { - console.log('SW registration failed: ', registrationError); - } - }); -} - createRoot(document.getElementById("root")!).render();