DHUVS FCM GATEWAY

Zero-Config Push for *.dhruvs.host

01 Create gateway-config.js

Place this in your website's root directory to define your branding.

COPY
const GATEWAY_CONFIG = {
  senderName: "My Website Name",
  icon: "https://your-site.dhruvs.host/logo.png"
};

02 Create firebase-messaging-sw.js

Place this in your website's root directory. It fetches your branding and talks to the gateway.

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

03 Add the Button & Script

Drop this HTML into your site. No JS setup required.

COPY
<!-- 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>

API ENDPOINTS

POST /send

Sends to the requesting subdomain's topic.

{ "message_subject": "Title Here", "message_body": "Message content here...", "icon": "https://img.url", "messenger_name": "Sender Name" }