Last active
August 25, 2018 22:12
-
-
Save whisher/4c5d577fe242965d4a24569d1c0321d1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.notification = (req, res, next) => { | |
const notificationPayload = { | |
notification: { | |
title: 'Blogial new post', | |
body: req.body.title, | |
icon: 'assets/icons/icon-512x512.png' | |
} | |
}; | |
Subscription.find() | |
.then(subscriptions => { | |
const promises = []; | |
subscriptions.forEach(subscription => { | |
promises.push( | |
webpush.sendNotification( | |
subscription, | |
JSON.stringify(notificationPayload)) | |
.then((response) => response) | |
); | |
}); | |
Promise.all(promises).then((response) => res.status(200).json(response)); | |
}).catch(error => { | |
res.status(500).json(error); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment