Zero-Config Push for *.dhruvs.host
gateway-config.js
Place this in your website's root directory to define your branding.
const GATEWAY_CONFIG = {
senderName: "My Website Name",
icon: "https://your-site.dhruvs.host/logo.png"
};
firebase-messaging-sw.js
Place this in your website's root directory. It fetches your branding and talks to the gateway.
importScripts('https://www.gstatic.com/firebasejs/10.8.0/firebase-app-compat.js');
importScripts('https://www.gstatic.com/firebasejs/10.8.0/firebase-messaging-compat.js');
firebase.initializeApp({
apiKey: "AIzaSyAccxtHdhMmMaYLesbRRGrXgzgM8I74uYU",
projectId: "appex-ca05f",
messagingSenderId: "251243500031",
appId: "1:251243500031:web:a031fe6c3f580e641117ca"
});
const messaging = firebase.messaging();
messaging.onBackgroundMessage(async (p) => {
let t = p.notification.title;
let b = p.notification.body;
let i = p.notification.image || "/default-icon.png";
try {
const r = await fetch('/gateway-config.js');
const txt = await r.text();
const sM = txt.match(/senderName:\s*["'](.+?)["']/);
const iM = txt.match(/icon:\s*["'](.+?)["']/);
if (sM) t = `${sM[1]}: ${t}`;
if (iM && !p.notification.image) i = iM[1];
} catch (e) {}
return self.registration.showNotification(t, { body: b, icon: i });
});
Drop this HTML into your site. No JS setup required.
<!-- The Button --> <button id="dhruvs-notify-btn">Enable Notifications</button> <p id="dhruvs-notify-status" style="display:none;"></p> <!-- The Script --> <script type="module" src="https://firebase-gateway.dhruvs.host/sign-up"></script>
/send
Sends to the requesting subdomain's topic.