-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
27 lines (23 loc) · 739 Bytes
/
index.js
File metadata and controls
27 lines (23 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const webpush = require('web-push');
// Public Key:
// BInQKHlWPIsQivVroJg83i7IhPOOXJbsrEITHoGzZfLiAoPY1hBvPl6ol432WBKr7xXqSeG7Kn5omHM_KfIPVZQ
//
// Private Key:
// 0kXMi_I8uuzRKsyvfmWwUPCD9Do8Knc9cEqpXQ1Zb7c
// VAPID keys should be generated only once.
const vapidKeys = webpush.generateVAPIDKeys();
webpush.setGCMAPIKey('<Your GCM API Key Here>');
webpush.setVapidDetails(
'mailto:example@yourdomain.org',
vapidKeys.publicKey,
vapidKeys.privateKey
);
// This is the same output of calling JSON.stringify on a PushSubscription
const pushSubscription = {
endpoint: '.....',
keys: {
auth: '.....',
p256dh: '.....'
}
};
webpush.sendNotification(pushSubscription, 'Your Push Payload Text');