Not crashing when not supplying push-data thingies

This commit is contained in:
Kasper Rynning-Tønnesen
2020-03-02 13:33:44 +01:00
parent 45c994d473
commit 6589425e54
6 changed files with 28 additions and 8 deletions

View File

@@ -9,12 +9,24 @@ mongoose.connect("mongodb://localhost:27017/vinlottis", {
useNewUrlParser: true
});
const config = require(path.join(__dirname + "/../config/env/push.config"));
const config = require(path.join(__dirname + "/../config/env/push"));
const Subscription = require(path.join(__dirname + "/../schemas/Subscription"));
const lotteryConfig = require(path.join(
__dirname + "/../config/env/lottery.config"
));
router.use((req, res, next) => {
next();
});
if (!config.publicKey) {
console.error(
"You are missing the push-setup! Server will continue running even without this."
);
module.exports = router;
return;
}
const vapidKeys = {
publicKey: config.publicKey,
privateKey: config.privateKey
@@ -34,10 +46,6 @@ const sendNotification = (subscription, dataToSend = "") => {
}
};
router.use((req, res, next) => {
next();
});
router.route("/save-subscription").post(async (req, res) => {
const subscription = req.body;
await saveToDatabase(subscription); //Method to save the subscription to Database