diff --git a/api/subscriptions.js b/api/subscriptions.js index ed6ea56..ed0f164 100644 --- a/api/subscriptions.js +++ b/api/subscriptions.js @@ -27,7 +27,11 @@ webpush.setVapidDetails( ); const sendNotification = (subscription, dataToSend = "") => { - webpush.sendNotification(subscription, dataToSend); + try { + webpush.sendNotification(subscription, dataToSend); + } catch (e) { + console.log("error", e); + } }; router.use((req, res, next) => { @@ -55,6 +59,19 @@ const saveToDatabase = async subscription => { } }; +router.route("/send-notification").post(async (req, res) => { + if (!req.isAuthenticated()) { + res.send(false); + return; + } + const message = req.body.message; + let subs = await Subscription.find(); + for (let i = 0; i < subs.length; i++) { + let subscription = subs[i]; //get subscription from your databse here. + sendNotification(subscription, message); + } +}); + schedule.scheduleJob( `0 50 ${lotteryConfig.hours - 1} * * ${lotteryConfig.date}`, async () => { diff --git a/src/components/RegisterPage.vue b/src/components/RegisterPage.vue index de91a07..b9c5f96 100644 --- a/src/components/RegisterPage.vue +++ b/src/components/RegisterPage.vue @@ -1,6 +1,15 @@