🎥🏑 Checkpoint

./server.js:7435365/533
This commit is contained in:
Glitch (hello-express) 2019-12-20 23:24:05 +00:00
parent 06aad43cf3
commit 451d581782

View File

@ -83,6 +83,9 @@ app.get('/getdata', (req, res) => {
// Handle requests to /cleanup by deleting any data older than 90 days from the datastore
app.get('/cleanup', (req, res) => {
// SECURITY CHECK FOR THE CORRECT CRONJOB HEADER GOES HERE!!
if (!req.headers['cleanup-key'] || req.headers['cleanup-key'] != process.env.SECRET) {
return res.status(401).send('Authorization header not found').end();
}
var before = new Date();
before.setDate(before.getDate()-91);
@ -96,8 +99,8 @@ app.get('/cleanup', (req, res) => {
[Op.lt]: before
}
}
}).then((result) => {
res.status(200).send(result).end();
}).then((numRows) => {
res.status(200).send('Deleted rows: ' + numRows).end();
});
});