Skip to content

Example web server using push notifications. Rust backend, JS.

License

Notifications You must be signed in to change notification settings

ducklol2/web_push_rust_example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Web Push Rust Example

Example web server using browser push notifications. Rust backend, JS in browser. Works in an iOS progressive web app (PWA)!

How to run

  1. 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.

  1. 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
  1. Run the server with:
cargo run
  1. 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.

  1. Click the buttons in sequence to create local notifications, register the service worker, and then push notifications from the server

  2. Visit & register with a second browser or device - a click from either will trigger notifications in both browsers!

Screenshots

Dependencies & recommended reading

About

Example web server using push notifications. Rust backend, JS.

Resources

License

Stars

Watchers

Forks