Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions PushMessageFromServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// https://felixgerschau.com/web-push-notifications-tutorial/
// https://developers.google.com/web/fundamentals/codelabs/push-notifications
const webPush = require('web-push');
const pushSubscription = require('./pushSubscription.json')

// VAPID keys should be generated only once with:
// const vapidKeys = webPush.generateVAPIDKeys();
Expand All @@ -18,16 +19,7 @@ webPush.setVapidDetails(
vapidKeys.privateKey
);

// This is an sample subscription object that we get after subscript on browser
const pushSubscription =
{
"endpoint": "",
"expirationTime": null,
"keys": {
"p256dh": "",
"auth": ""
}
}
// pushSubscription is an sample subscription object that we get after subscript on browser

const payload = {
title: `Hello at ${(new Date()).toISOString()}`,
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


# Send push notification from a server
- Set a push subscription object that we get after a user's subscribed web push in `PushMessageFromServer.js`
- Set a push subscription object that we get after a user's subscribed web push in `pushSubscription.json`
- Then execute the following command:
```sh
$ node PushMessageFromServer.js
Expand Down
8 changes: 8 additions & 0 deletions pushSubscription.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"endpoint": "https://fcm.googleapis.com/fcm/send/dDEsIVpevRQ:APA91bFG6umABbc7IVuCQqc2TNx0Ramrnm0hnLr7CWsgr52AeJh7OPwOUoLMrv3sK8WmwEgsfpgH3kXrEKzOj5fMG5cWpFd_ZyocQhqe6Gt5vy1cPXEPe01grF1IL-bqxQRVDqhm-6e-",
"expirationTime": null,
"keys": {
"p256dh": "BC_wvLFfABtfoqusJKwsNqJAyDz-rIvAIg9YfB_z7lemXNFkzBLeLd9PTKGbeQTTflYqLZvIiT-lZHsA7BHZUDo",
"auth": "LigA_xph0Wlygf0WkYq_gA"
}
}