- risolto problema della non attesa della PWA durante la chiamata a Node.js.
- risolto problema dell'ambiente in Locale HTTPS certificato installato aggiornato.
This commit is contained in:
@@ -26,7 +26,7 @@ import {
|
||||
import { CacheableResponsePlugin } from 'workbox-cacheable-response';
|
||||
import { ExpirationPlugin } from 'workbox-expiration';
|
||||
|
||||
const debug = process.env.NODE_ENV !== 'production';
|
||||
const debug = false; //process.env.NODE_ENV !== 'production';
|
||||
|
||||
if (workbox) {
|
||||
|
||||
@@ -122,14 +122,14 @@ async function deleteItemFromData(table, id) {
|
||||
if (workbox) {
|
||||
|
||||
|
||||
if (process.env.MODE !== 'ssr' || process.env.PROD) {
|
||||
/*if (process.env.MODE !== 'ssr' || process.env.PROD) {
|
||||
registerRoute(
|
||||
new NavigationRoute(
|
||||
createHandlerBoundToURL(process.env.PWA_FALLBACK_HTML),
|
||||
{ denylist: [new RegExp(process.env.PWA_SERVICE_WORKER_REGEX), /workbox\workbox-(.)*\.js$/] }
|
||||
)
|
||||
)
|
||||
}
|
||||
}*/
|
||||
|
||||
// Cache strategy registrations
|
||||
registerRoute(
|
||||
@@ -257,7 +257,11 @@ if (workbox) {
|
||||
if (ISTEST) {
|
||||
API_DOMAIN = 'testapi.' + removeTestPrefix(APP_DOMAIN);
|
||||
} else {
|
||||
API_DOMAIN = 'api.' + APP_DOMAIN;
|
||||
if (APP_DOMAIN.includes('localhost')) {
|
||||
API_DOMAIN = 'localhost:3000';
|
||||
} else {
|
||||
API_DOMAIN = 'api.' + APP_DOMAIN;
|
||||
}
|
||||
}
|
||||
|
||||
console.log('API_DOMAIN', API_DOMAIN);
|
||||
@@ -304,19 +308,19 @@ if (workbox) {
|
||||
}
|
||||
|
||||
// Strategia di caching: stale-while-revalidate
|
||||
async function cacheWithStaleWhileRevalidate(request) {
|
||||
async function cacheWithStaleWhileRevalidate(request, event) {
|
||||
const cache = await caches.open(CACHE_NAME);
|
||||
|
||||
// Prova a recuperare la risorsa dalla cache
|
||||
const cachedResponse = await cache.match(request);
|
||||
if (cachedResponse) {
|
||||
// Restituisci la risposta in cache mentre aggiorni in background
|
||||
fetchAndCache(request);
|
||||
event.waitUntil(fetchAndCache(request));
|
||||
return cachedResponse;
|
||||
}
|
||||
|
||||
// Se non è in cache, fai la richiesta di rete
|
||||
return fetchAndCache(request);
|
||||
return await fetchAndCache(request);
|
||||
}
|
||||
|
||||
// Funzione per fare la richiesta di rete e aggiornare la cache
|
||||
@@ -357,7 +361,7 @@ if (workbox) {
|
||||
console.log('E\' una RICHIESTA statica...')
|
||||
}
|
||||
// Gestione risorse statiche e altre richieste
|
||||
event.respondWith(cacheWithStaleWhileRevalidate(request));
|
||||
event.respondWith(cacheWithStaleWhileRevalidate(request, event));
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user