mirror of
https://github.com/imjasonh/webpush
synced 2026-07-06 23:52:25 +00:00
|
|
||
|---|---|---|
| .. | ||
| static | ||
| .gitignore | ||
| main.go | ||
| README.md | ||
Web Push Example
A complete example demonstrating the web push library with:
- VAPID keys stored on disk (auto-generated on first run)
- SQLite storage for subscriptions
- Web client for subscribing to notifications
- Automatic push every minute
- Manual push via
/pingendpoint
Running
cd example
go run main.go
Then open http://localhost:8080 in your browser.
Features
- Subscribe: Click "Subscribe to Notifications" to register for push notifications
- Automatic Pushes: Notifications are sent every minute to all subscribers
- Manual Pushes: Visit
/pingor click "Send Ping" to trigger an immediate push
Files Generated
On first run, the example generates:
vapid-private.pem- VAPID private key (keep this secret!)subscriptions.db- SQLite database for storing subscriptions
Endpoints
GET /- Web client UIGET /sw.js- Service worker for handling push eventsGET /api/vapid-public-key- Returns the VAPID public keyPOST /api/subscribe- Register a new subscriptionPOST /api/unsubscribe- Remove a subscriptionGET /ping- Send push to all subscribers (optional?title=and?body=query params)