- fix: nModified è stato sostituito con modifiedCount
- .ok con .acknowledged - coretto la chiamata per il REFRESH TOKEN !
This commit is contained in:
@@ -3,9 +3,9 @@
|
||||
/* global workbox */
|
||||
/* global cfgenv */
|
||||
|
||||
const CACHE_NAME = 'pwa-cache-v2'; // Nome della cache
|
||||
const VITE_APP_VERSION = "1.2.19";
|
||||
|
||||
const ORA = "12.57"
|
||||
const CACHE_NAME = 'pwa-cache-' + VITE_APP_VERSION; // Nome della cache
|
||||
|
||||
importScripts('workbox/workbox-sw.js')
|
||||
|
||||
@@ -31,7 +31,7 @@ if (workbox) {
|
||||
|
||||
workbox.loadModule('workbox-strategies');
|
||||
|
||||
console.log('Workbox ESISTE ✅ ' + ORA);
|
||||
console.log('Workbox ESISTE ✅ ');
|
||||
|
||||
} else {
|
||||
console.error('Workbox NON CARICATO ! ❌');
|
||||
@@ -73,16 +73,15 @@ self.addEventListener('activate', (event) => {
|
||||
caches.keys().then((cacheNames) => {
|
||||
return Promise.all(
|
||||
cacheNames
|
||||
.filter((name) => name !== CACHE_NAME)
|
||||
.filter(name => name !== CACHE_NAME && name !== DYNAMIC_CACHE)
|
||||
.map((name) => caches.delete(name))
|
||||
);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
const VITE_APP_VERSION = "1.2.18";
|
||||
|
||||
console.log(' [ VER-' + VITE_APP_VERSION + ' ] _---------________------ PAO: this is my custom service worker: ' + ORA);
|
||||
console.log(' [ VER-' + VITE_APP_VERSION + ' ] _---------________------ PAO: this is my custom service worker: ');
|
||||
|
||||
try {
|
||||
importScripts('/js/idb.js', '/js/storage.js');
|
||||
@@ -127,6 +126,12 @@ if (workbox) {
|
||||
)
|
||||
}*/
|
||||
|
||||
// Gestione richieste statiche
|
||||
registerRoute(
|
||||
({ request }) => request.destination === 'document' || request.destination === 'script' || request.destination === 'style',
|
||||
new StaleWhileRevalidate({ cacheName: CACHE_NAME })
|
||||
);
|
||||
|
||||
// Cache strategy registrations
|
||||
registerRoute(
|
||||
new RegExp(/\.(?:png|gif|jpg|jpeg)$/),
|
||||
@@ -182,7 +187,13 @@ if (workbox) {
|
||||
})
|
||||
);
|
||||
|
||||
// Gestione API
|
||||
registerRoute(
|
||||
({ url }) => url.hostname === API_DOMAIN,
|
||||
new NetworkOnly({ fetchOptions: { credentials: 'include' } })
|
||||
);
|
||||
|
||||
/*registerRoute(
|
||||
(routeData) => routeData.event.request.headers.get('accept').includes('text/html'),
|
||||
async (args) => {
|
||||
let response = await caches.match(args.event.request);
|
||||
@@ -197,7 +208,7 @@ if (workbox) {
|
||||
return caches.match('/offline');
|
||||
}
|
||||
}
|
||||
);
|
||||
);*/
|
||||
|
||||
registerRoute(new RegExp('/admin/'), new NetworkOnly());
|
||||
|
||||
@@ -268,7 +279,6 @@ if (workbox) {
|
||||
method: request.method,
|
||||
headers: {
|
||||
...Object.fromEntries(request.headers.entries()),
|
||||
'Origin': `https://${APP_DOMAIN}`,
|
||||
'Accept': 'application/json',
|
||||
},
|
||||
mode: 'cors',
|
||||
@@ -278,13 +288,15 @@ if (workbox) {
|
||||
try {
|
||||
const response = await fetch(modifiedRequest);
|
||||
|
||||
if (!response.ok) {
|
||||
console.warn('[SW] API Response Error:', response.status, response.statusText);
|
||||
}
|
||||
|
||||
// Se la risposta è valida, restituiscila
|
||||
if (response.ok) {
|
||||
return response;
|
||||
}
|
||||
|
||||
// Logga eventuali errori
|
||||
console.warn('[Service Worker] API response not OK:', response.status, response.statusText);
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error('[Service Worker] API request error ❌:', error);
|
||||
|
||||
Reference in New Issue
Block a user