app.post('/api/save-subscription/', function (req, res) { if (!isValidSaveRequest(req, res)) { return; }
returnsaveSubscriptionToDatabase(req.body) .then(function(subscriptionId) { res.setHeader('Content-Type', 'application/json'); res.send(JSON.stringify({ data: { success: true } })); }) .catch(function(err) { res.status(500); res.setHeader('Content-Type', 'application/json'); res.send(JSON.stringify({ error: { id: 'unable-to-save-subscription', message: 'The subscription was received but we were unable to save it to our database.' } })); }); });
// This is the same output of calling JSON.stringify on a PushSubscription const pushSubscription = { endpoint: '.....', keys: { auth: '.....', p256dh: '.....' } };