-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpushServer.js
20 lines (16 loc) · 908 Bytes
/
pushServer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const webPush = require('web-push');
const pushServerKeys = require('./pushServerKeys.json');
const pushClientSubscription = require('./pushClientSubscription.json');
webPush.setVapidDetails('mailto:contact@codeconcept.fr', pushServerKeys.publicKey, pushServerKeys.privateKey);
const subscription = {
endpoint: pushClientSubscription.endpoint,
keys: {
auth: pushClientSubscription.keys.auth,
p256dh: pushClientSubscription.keys.p256dh
}
};
// TODO retrieve all users subscriptions and send the push notification to every user
// see https://github.com/web-push-libs/web-push for sendNotification API reference sendNotification(pushSubscription, payload, options)
webPush.sendNotification(subscription, 'Notification envoyée depuis le serveur push node :)')
.then(res => console.log('ma push notif a bien été poussée :)', res))
.catch(err => console.error);