Subdomains / Wildcards
How to setup worker in one file for multiple subdomains
π οΈ Configuring a Single Service Worker for Multiple Projects
π¦ Use Case
π§ Solution
π Example sw.js Implementation
sw.js Implementation// Map subdomains to PushPushGo project IDs
const idsMap = {
'aaa.example.com': 'firstProjectId', // Replace with real ID
'bbb.example.com': 'secondProjectId', // Replace with real ID
// Add more domains as needed
};
let id = null;
// Determine the current subdomain
if (idsMap[self.location.hostname]) {
id = idsMap[self.location.hostname];
}
if (id) {
// Import the correct PushPushGo worker
importScripts(`https://s-eu-1.pushpushgo.com/${id}/worker.js`);
} else {
console.warn('[PushPushGo] No project ID configured for this domain:', self.location.hostname);
}π Notes
πͺ Debugging Tips
β
Advantages
π Need Help?
Last updated