-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3854629
commit 72f4619
Showing
4 changed files
with
138 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"name": "DebateThing.com", | ||
"short_name": "DebateThing", | ||
"description": "An experimental tool for creating simulated debates using AI", | ||
"icons": [ | ||
{ | ||
"src": "/favicon-16x16.png", | ||
"sizes": "16x16", | ||
"type": "image/png" | ||
}, | ||
{ | ||
"src": "/favicon-32x32.png", | ||
"sizes": "32x32", | ||
"type": "image/png" | ||
}, | ||
{ | ||
"src": "/apple-touch-icon.png", | ||
"sizes": "180x180", | ||
"type": "image/png" | ||
}, | ||
{ | ||
"src": "/img/512.png", | ||
"sizes": "512x512", | ||
"type": "image/png" | ||
} | ||
], | ||
"theme_color": "#1881F2", | ||
"background_color": "#ffffff", | ||
"display": "standalone", | ||
"orientation": "any", | ||
"start_url": "/", | ||
"scope": "/", | ||
"lang": "en-US" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> | ||
<url> | ||
<loc>https://www.debatething.com/</loc> | ||
<lastmod>2024-09-02</lastmod> | ||
<changefreq>daily</changefreq> | ||
<priority>1.0</priority> | ||
</url> | ||
</urlset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
const CACHE_NAME = 'debatething-cache-v1'; | ||
const urlsToCache = [ | ||
'/', | ||
'/styles.css', | ||
'/favicon.ico', | ||
'/favicon-16x16.png', | ||
'/favicon-32x32.png', | ||
'/apple-touch-icon.png', | ||
'/safari-pinned-tab.svg', | ||
'/site.webmanifest', | ||
]; | ||
|
||
self.addEventListener('install', (event) => { | ||
event.waitUntil( | ||
caches.open(CACHE_NAME) | ||
.then((cache) => { | ||
return Promise.all( | ||
urlsToCache.map(url => { | ||
return fetch(url) | ||
.then(response => { | ||
if (!response.ok) { | ||
throw new Error(`Failed to fetch ${url}`); | ||
} | ||
return cache.put(url, response); | ||
}) | ||
.catch(error => { | ||
console.error('Caching failed for', url, error); | ||
return Promise.resolve(); | ||
}); | ||
}) | ||
); | ||
}) | ||
); | ||
}); | ||
|
||
self.addEventListener('fetch', (event) => { | ||
// Check if the request is a POST request | ||
if (event.request.method === 'POST') { | ||
// For POST requests, bypass the cache and fetch from the network | ||
event.respondWith(fetch(event.request)); | ||
return; | ||
} | ||
|
||
// For non-POST requests, use the cache-first strategy | ||
event.respondWith( | ||
caches.match(event.request) | ||
.then((response) => { | ||
if (response) { | ||
return response; | ||
} | ||
return fetch(event.request).then( | ||
(response) => { | ||
if (!response || response.status !== 200 || response.type !== 'basic') { | ||
return response; | ||
} | ||
const responseToCache = response.clone(); | ||
caches.open(CACHE_NAME) | ||
.then((cache) => { | ||
cache.put(event.request, responseToCache); | ||
}); | ||
return response; | ||
} | ||
); | ||
}) | ||
); | ||
}); | ||
|
||
self.addEventListener('activate', (event) => { | ||
const cacheWhitelist = [CACHE_NAME]; | ||
event.waitUntil( | ||
caches.keys().then((cacheNames) => { | ||
return Promise.all( | ||
cacheNames.map((cacheName) => { | ||
if (cacheWhitelist.indexOf(cacheName) === -1) { | ||
return caches.delete(cacheName); | ||
} | ||
}) | ||
); | ||
}) | ||
); | ||
}); |