import {
createWebAppManifest,
pushServiceWorker,
createWebPush,
} from "@absolutejs/pwa";
const ICON = "/icons/app-512.png";
// Serve as application/manifest+json at /manifest.webmanifest
export const manifest = createWebAppManifest({
name: "My App",
shortName: "MyApp",
themeColor: "#6366f1",
icons: [
{ src: ICON, sizes: "192x192", type: "image/png", purpose: "any" },
{ src: ICON, sizes: "512x512", type: "image/png", purpose: "any" },
],
});
// Serve as text/javascript at /sw.js with header `Service-Worker-Allowed: /`.
// Pass `offline` to also precache an app shell + serve a fallback page when a
// navigation fails offline, and cache same-origin assets cache-first.
export const sw = pushServiceWorker({
icon: ICON,
offline: { fallback: "/offline.html", assetPrefix: "/assets/" },
});
// VAPID sender — pass empty/unset keys and it no-ops (isConfigured() === false),
// so push degrades gracefully to your email/in-app fallback.
const push = createWebPush({
publicKey: process.env.VAPID_PUBLIC_KEY,
privateKey: process.env.VAPID_PRIVATE_KEY,
subject: "mailto:you@example.com",
});
// Fan out to a user's devices; prune whatever it reports gone.
const { gone } = await push.sendMany(subscriptions, {
title: "New match",
body: "Acme Co. just replied.",
url: "/inbox",
});
await pruneEndpoints(gone); // your storage