Example web server using browser push notifications. Rust backend, JS in browser. Works in an iOS progressive web app (PWA)!
- Clone this repository, or open as a GitHub Codespace.
Tip
Codespaces let you develop & test directly from your browser, and even forward the server port to visit with a mobile device.
- From the repo root directory, generate public & private keys, which are necessary for browser web push:
openssl ecparam -genkey -name prime256v1 -out private_key.pem
openssl ec -in private_key.pem -pubout -outform DER|tail -c 65|base64|tr '/+' '_-'|tr -d '\n=' > static/public_key.txt
- Run the server with:
cargo run
- Visit the website - either at http://localhost:3000, or at the created URL if in a Codespace.
Note
If on iOS, add as PWA (Share --> Add to Home Screen) so that notifications work.
-
Click the buttons in sequence to create local notifications, register the service worker, and then push notifications from the server
-
Visit & register with a second browser or device - a click from either will trigger notifications in both browsers!
- Axum, a Rust server framework
- web-push, a Rust library that communicates with browser push servers
- The web.dev Notifications documentation, which explains how browser push works.