feat(site): add webpush notification serviceworker (#17123)

* Improves tests for webpush notifications
* Sets subscriber correctly in web push payload (without this,
notifications do not work in Safari)
* NOTE: for now, I'm using the Coder Access URL. Some push messaging
service don't like it when you use a non-HTTPS URL, so dropping a warn
log about this.
* Adds a service worker and context for push notifications
* Adds a button beside "Inbox" to enable / disable push notifications

Notes:
*  Tested in in Firefox and Safari, and Chrome.
This commit is contained in:
Cian Johnston
2025-03-27 17:30:25 +00:00
committed by GitHub
parent 661ed2376a
commit e1f27a7137
11 changed files with 285 additions and 52 deletions
+18
View File
@@ -1,5 +1,6 @@
import * as path from "node:path";
import react from "@vitejs/plugin-react";
import { buildSync } from "esbuild";
import { visualizer } from "rollup-plugin-visualizer";
import { type PluginOption, defineConfig } from "vite";
import checker from "vite-plugin-checker";
@@ -28,6 +29,19 @@ export default defineConfig({
emptyOutDir: false,
// 'hidden' works like true except that the corresponding sourcemap comments in the bundled files are suppressed
sourcemap: "hidden",
rollupOptions: {
input: {
index: path.resolve(__dirname, "./index.html"),
serviceWorker: path.resolve(__dirname, "./src/serviceWorker.ts"),
},
output: {
entryFileNames: (chunkInfo) => {
return chunkInfo.name === "serviceWorker"
? "[name].js"
: "assets/[name]-[hash].js";
},
},
},
},
define: {
"process.env": {
@@ -89,6 +103,10 @@ export default defineConfig({
target: process.env.CODER_HOST || "http://localhost:3000",
secure: process.env.NODE_ENV === "production",
},
"/serviceWorker.js": {
target: process.env.CODER_HOST || "http://localhost:3000",
secure: process.env.NODE_ENV === "production",
},
},
allowedHosts: true,
},