Fix Applied: Push Notifications Now Deliver When App Is Closed
Previously, push notifications failed when closed because the Service Worker was missing direct Web Push listeners and root scope bindings. We implemented:
/firebase-messaging-sw.js listens 24/7 in background.
Dual Firebase compat & native push listener catches all payloads.
Standalone manifest enables background push on iOS 16.4+ & Android.
Device Permission & FCM Token
Permission status: DEFAULT
Test 1: App Closed Simulator
Want to test immediately on your phone or laptop? Click the button below, then lock your screen or minimize the browser tab. The Service Worker will wake up in 5 seconds and deliver the push banner!
Test 2: Cloud Messaging Push
Send from Terminal / Backend (cURL Example)
curl -X POST https://fcm.googleapis.com/fcm/send \
-H "Content-Type: application/json" \
-H "Authorization: key=YOUR_FCM_SERVER_KEY" \
-d '{
"to": "DEVICE_FCM_TOKEN",
"priority": "high",
"notification": {
"title": "BunkClub Alert",
"body": "Hey! Testing push when the app is closed 🚀",
"icon": "/icons/icon-192.png",
"click_action": "/"
},
"webpush": {
"headers": { "Urgency": "high" },
"notification": { "requireInteraction": true }
}
}'How to Host on Hostinger
Run npm run build in static export mode. Next.js generates an out/ directory. Simply open Hostinger File Manager and upload all contents of out/ into your public_html! Ensure SSL (HTTPS) is activated in Hostinger (free Let's Encrypt), because Web Push requires HTTPS.
Upload this project, run npm install, then npm run build, and start it with PM2 or npm start.