Skip to content

Instantly share code, notes, and snippets.

@whisher
Last active August 25, 2018 22:12
Show Gist options
  • Save whisher/4c5d577fe242965d4a24569d1c0321d1 to your computer and use it in GitHub Desktop.
Save whisher/4c5d577fe242965d4a24569d1c0321d1 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)
);
});
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