This repository contains a basic demo for web push.
- Clone the repo
npm install
- Install mkcert so https works (see Help section below)
- Create the environment
- Copy
.env.template
to.env
- Generate VAPID keys and set
VAPID_PUBLIC_KEY
andVAPID_PRIVATE_KEY
in the.env
file - Set
VAPID_SUBJECT
tomailto:
your email address
- Copy
npm run start
- Point your browser to https://localhost
- Grant permission for notifications
- Send a notification (see APIs below)
curl --location 'https://localhost/api/key'
curl --location 'https://localhost/api/subscriptions'
curl --location 'https://localhost/api/send-notification' \
--header 'Content-Type: application/json' \
--data '{
"title": "Flash sale",
"message": "Don'\''t miss out!",
"url": "/"
}'
- Follow the readme to install mkcert on your computer.
- Once installed, run
mkcert -install
to install the mkcert root certificate.
- Install the web-push cli
npm i -g web-push
- Generate keys
web-push generate-vapid-keys