```
✨ feat(sw.js): Ajoute la gestion des notifications push et simplifie le SW. 🔧 chore(framework.yaml): Configure les proxies de confiance pour Cloudflare. ```
This commit is contained in:
@@ -7,7 +7,8 @@ framework:
|
||||
|
||||
#esi: true
|
||||
#fragments: true
|
||||
|
||||
trusted_proxies: '103.21.244.0/22,103.22.200.0/22,103.31.4.0/22,104.16.0.0/12,108.162.192.0/18,131.0.72.0/22,141.101.64.0/18,162.158.0.0/15,172.64.0.0/13,173.245.48.0/20,188.114.96.0/20,190.93.240.0/20,197.234.240.0/22,198.41.128.0/17'
|
||||
trusted_headers: [ 'x-forwarded-for', 'x-forwarded-host', 'x-forwarded-proto', 'x-forwarded-port', 'x-forwarded-prefix' ]
|
||||
when@test:
|
||||
framework:
|
||||
test: true
|
||||
|
||||
36
public/sw.js
36
public/sw.js
@@ -1,40 +1,16 @@
|
||||
// This is the service worker with the combined offline experience (Offline page + Offline copy of pages)
|
||||
|
||||
const CACHE = "pwabuilder-offline-page";
|
||||
|
||||
importScripts('https://storage.googleapis.com/workbox-cdn/releases/5.1.2/workbox-sw.js');
|
||||
|
||||
// TODO: replace the following with the correct offline fallback page i.e.: const offlineFallbackPage = "offline.html";
|
||||
const offlineFallbackPage = "offline.html";
|
||||
// --- Service Worker pour la gestion des Notifications Push ---
|
||||
|
||||
// Permet au Service Worker de s'activer immédiatement après l'installation
|
||||
self.addEventListener("message", (event) => {
|
||||
if (event.data && event.data.type === "SKIP_WAITING") {
|
||||
self.skipWaiting();
|
||||
}
|
||||
});
|
||||
|
||||
self.addEventListener('install', async (event) => {
|
||||
event.waitUntil(
|
||||
caches.open(CACHE)
|
||||
.then((cache) => cache.add(offlineFallbackPage))
|
||||
);
|
||||
});
|
||||
|
||||
if (workbox.navigationPreload.isSupported()) {
|
||||
workbox.navigationPreload.enable();
|
||||
}
|
||||
|
||||
workbox.routing.registerRoute(
|
||||
new RegExp('/*'),
|
||||
new workbox.strategies.StaleWhileRevalidate({
|
||||
cacheName: CACHE
|
||||
})
|
||||
);
|
||||
|
||||
// --- GESTION DES NOTIFICATIONS PUSH (Réception) ---
|
||||
self.addEventListener('push', (event) => {
|
||||
if (event.data) {
|
||||
// Assurez-vous que le payload JSON envoyé par votre serveur contient
|
||||
// Le payload JSON envoyé par votre serveur doit contenir
|
||||
// 'title', 'message' et 'link'.
|
||||
const data = event.data.json();
|
||||
|
||||
@@ -44,7 +20,7 @@ self.addEventListener('push', (event) => {
|
||||
|
||||
const options = {
|
||||
body: message,
|
||||
// PATH MIS À JOUR ICI
|
||||
// PATH MIS À JOUR ICI : Assurez-vous que l'icône est accessible
|
||||
icon: data.icon || '/assets/notif.png',
|
||||
data: {
|
||||
link: link // On stocke le lien pour le réutiliser au clic
|
||||
@@ -70,9 +46,9 @@ self.addEventListener('notificationclick', (event) => {
|
||||
event.waitUntil(
|
||||
clients.matchAll({ type: 'window', includeUncontrolled: true }).then((clientList) => {
|
||||
|
||||
// Tente de trouver un client existant pour naviguer
|
||||
// Tente de trouver un client existant pour naviguer (si l'URL est déjà ouverte)
|
||||
for (const client of clientList) {
|
||||
if (client.url.endsWith(urlToOpen) && 'focus' in client) {
|
||||
if (client.url.includes(urlToOpen) && 'focus' in client) {
|
||||
return client.focus();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user