根据教程写了这么一段代码:
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)
})
})
saveRegistrationDetails主要原因是,这个方法不知道哪里来的。。