FCM Gateway

Zero-config push notifications for *.dhruvs.host

Quick Start Integration

No Firebase keys required on your end. Just follow these three steps to enable notifications on your subdomain.

1 Configure Branding (gateway-config.js)

Create this file in your website's root directory to set your sender name and logo.

Copy
const GATEWAY_CONFIG = {
  senderName: "My Awesome Site",
  icon: "https://yourdomain.dhruvs.host/logo.png"
};

2 Add Service Worker (firebase-messaging-sw.js)

Place this file in your root directory. This file contains the pre-configured gateway logic.

Copy
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 });
});

3 Drop-in the Button

Paste this into your HTML. The script automatically handles registration and permissions.

Copy
<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>

Backend API Reference

POST /send

Broadcast a message to your subdomain's subscribers.

{ "message_subject": "Hello World", "message_body": "This is a test notification.", "icon": "https://example.com/alert.png", "messenger_name": "Alert System" }