https://github.com/toumash/webpush-demo
Simple demo showing an implementation sample of web-push with nodejs
https://github.com/toumash/webpush-demo
demo nodejs web-push-notification
Last synced: about 1 month ago
JSON representation
Simple demo showing an implementation sample of web-push with nodejs
- Host: GitHub
- URL: https://github.com/toumash/webpush-demo
- Owner: Toumash
- Created: 2020-03-25T22:05:02.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-12T07:20:37.000Z (over 3 years ago)
- Last Synced: 2026-03-03T23:45:43.186Z (3 months ago)
- Topics: demo, nodejs, web-push-notification
- Language: JavaScript
- Homepage:
- Size: 38.1 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Web Push Demo
## Wymagania
- Zainstalowany nodejs
# How to run?
```
npm install
node ./generate-vapid.js # copy these keys to server.js and index.html
node ./server.js
```
## Jak to działa?
1. Wygeneruj klucze VAPID
```shell
node ./vapidkey-generator.js
```
2. Rejestracja service workera
Następuje po wejściu na stronę przez użytkownika. Service worker to javascript chodzący w tle nawet po zamknięciu karty.
```js
var sw = await navigator.serviceWorker.register("./sw.js");
console.log("service worker registered!", sw);
```
3. Użytkownik zgadza się na subscrypcję
```js
var sw = await navigator.serviceWorker.ready;
var pushInfo = await sw.pushManager.subscribe({
userVisibleOnly: true,
applicationServerKey:
"