Forked from whisher/gist:4c5d577fe242965d4a24569d1c0321d1
Last active
August 26, 2018 14:11
-
-
Save mcollina/37cf9ba13a381298ff4623b12be23037 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) | |
); | |
}); | |
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