Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mcollina/37cf9ba13a381298ff4623b12be23037 to your computer and use it in GitHub Desktop.
Save mcollina/37cf9ba13a381298ff4623b12be23037 to your computer and use it in GitHub Desktop.
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)
);
});
return 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