Zero-config push notifications for *.dhruvs.host
No Firebase keys required on your end. Just follow these three steps to enable notifications on your subdomain.
Create this file in your website's root directory to set your sender name and logo.
const GATEWAY_CONFIG = {
senderName: "My Awesome Site",
icon: "https://yourdomain.dhruvs.host/logo.png"
};
Place this file in your root directory. This file contains the pre-configured gateway logic.
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 (payload) => {
let title = payload.notification.title;
let body = payload.notification.body;
let icon = payload.notification.image || "/default-icon.png";
try {
const res = await fetch('/gateway-config.js');
const text = await res.text();
const sMatch = text.match(/senderName:\s*["'](.+?)["']/);
const iMatch = text.match(/icon:\s*["'](.+?)["']/);
if (sMatch) title = `${sMatch[1]}: ${title}`;
if (iMatch && !payload.notification.image) icon = iMatch[1];
} catch (e) {}
return self.registration.showNotification(title, { body, icon });
});
Paste this into your HTML. The script automatically handles registration and permissions.
<button id="dhruvs-notify-btn">Enable Notifications</button> <p id="dhruvs-notify-status" style="display:none;"></p> <script type="module" src="https://firebase-gateway.dhruvs.host/sign-up"></script>
/send
Broadcast a message to your subdomain's subscribers.