An API driven push notification service based on NodeJS written in TypeScript.
It saves push subscriptions to a MongoDB and let's you then send a push to those subscriptions using the HTTPWebPush.
Make sure to have a look at my Push Notification Demo for a possible client-side integration.
The service requires some environment variables:
DATABASE_URL
The URL to the MongoDBVAPID_EMAIL
an email address used for VAPID verificationVAPID_PRIVATE_KEY
VAPID Private KeyVAPID_PUBLIC_KEY
VAPID Public KeyAUTH_ADMIN_PASSWORD
(optional) if you want to you can secure the push endpoint using a basic auth admin/AUTH_ADMIN_PASSWORD
The Voluntary Application Server Identification (VAPID) is used to encrypt push notification data and identify the application server to a push service.
The private/public keypair can be generated here: https://tools.reactpwa.com/vapid
Get the Uint8Array version of the VAPID_PUBLIC_KEY
that can be used as the applicationServerKey
for the ServiceWorkerRegistration.pushManager.subscribe
-Method.
Add a push subscription to the DB
Check if endpoint is in the DB
Delete endpoint from the DB
Header:
Content-Type: application/json
Body:
{
"endpoint": "subscription.endpoint",
"p256dh": "subscription.p256dh",
"auth": "subscription.auth"
}
Send a push notification to all clients
Header:
Content-Type: application/json
Body:
{
"title": "My Push",
"body": "This is my push notification"
}