wrote this code according to the tutorial:
app.post("/register", jsonParser, function(req, res) {
var endpoint = req.body.endpoint
var key = req.body.key
var authSecret = req.body.authSecret
console.log(saveSubscriptionToDatabase)
//
//
saveRegistrationDetails(endpoint, key, authSecret)
console.log(11)
const pushSubscription = {
endpoint: req.body.endpoint,
keys: {
auth: req.body.authSecret,
p256dh: req.body.key
}
}
var body = "thank u for registering"
var iconUrl = "/icon.png"
//
webpush.sendNotification(pushSubscription,
JSON.stringify({
msg: body,
url: "http://localhost:3001/pwa",
icon: iconUrl
})
).then( response => {
res.sendStatus(201)
}).catch(err => {
console.log(err)
})
})
The main reason for saveRegistrationDetails is that I don"t know where this method came from.