hh-shipments 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/public/sw.js +11 -3
- package/server.js +9 -0
package/package.json
CHANGED
package/public/sw.js
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
|
-
/* Service worker: app-shell cache + web-push handling
|
|
2
|
-
|
|
1
|
+
/* Service worker: app-shell cache + web-push handling.
|
|
2
|
+
CACHE name includes the app version (injected by the server), so every
|
|
3
|
+
deploy installs a fresh shell and deletes the old one. */
|
|
4
|
+
const CACHE = 'hh-ship-__APP_VERSION__';
|
|
3
5
|
const SHELL = ['/', '/index.html', '/styles.css', '/app.js', '/extract.js', '/manifest.webmanifest'];
|
|
4
6
|
|
|
5
7
|
self.addEventListener('install', (e) => {
|
|
6
8
|
e.waitUntil(caches.open(CACHE).then((c) => c.addAll(SHELL)).then(() => self.skipWaiting()));
|
|
7
9
|
});
|
|
8
|
-
self.addEventListener('activate', (e) => {
|
|
10
|
+
self.addEventListener('activate', (e) => {
|
|
11
|
+
e.waitUntil(
|
|
12
|
+
caches.keys()
|
|
13
|
+
.then((keys) => Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k))))
|
|
14
|
+
.then(() => self.clients.claim())
|
|
15
|
+
);
|
|
16
|
+
});
|
|
9
17
|
self.addEventListener('fetch', (e) => {
|
|
10
18
|
if (e.request.method !== 'GET' || !e.request.url.startsWith(self.location.origin)) return;
|
|
11
19
|
if (e.request.url.includes('/api/')) return; // never cache API
|
package/server.js
CHANGED
|
@@ -569,6 +569,15 @@ cron.schedule('0 8 * * *', async () => {
|
|
|
569
569
|
});
|
|
570
570
|
|
|
571
571
|
/* ---------------- static frontend ---------------- */
|
|
572
|
+
// Serve sw.js dynamically so the cache name tracks the app version —
|
|
573
|
+
// every deploy busts the old app-shell cache on the next visit.
|
|
574
|
+
const APP_VERSION = require('./package.json').version;
|
|
575
|
+
app.get('/sw.js', (req, res) => {
|
|
576
|
+
fs.readFile(path.join(__dirname, 'public', 'sw.js'), 'utf8', (err, src) => {
|
|
577
|
+
if (err) return res.sendStatus(404);
|
|
578
|
+
res.type('application/javascript').set('Cache-Control', 'no-cache').send(src.replace(/__APP_VERSION__/g, APP_VERSION));
|
|
579
|
+
});
|
|
580
|
+
});
|
|
572
581
|
app.use(express.static(path.join(__dirname, 'public')));
|
|
573
582
|
app.get('*', (req, res) => res.sendFile(path.join(__dirname, 'public', 'index.html')));
|
|
574
583
|
|