diff --git a/.gitignore b/.gitignore index b512c09..34977ee 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -node_modules \ No newline at end of file +node_modules +.idea \ No newline at end of file diff --git a/main.js b/main.js index 490c201..f751a94 100644 --- a/main.js +++ b/main.js @@ -17,7 +17,7 @@ app.get('/', async (req, res) => { const url = req.query.url; if (!url) { - res.status(400).send("nop"); + res.status(400).contentType("text/plain").send("nop"); return; } @@ -30,7 +30,7 @@ app.get('/', async (req, res) => { if (row) { const currentTime = getCurrentUnixTimestamp(); - const twoHoursInSeconds = 10; + const twoHoursInSeconds = 7200; if (currentTime - row.time > twoHoursInSeconds) { db.run(`DELETE FROM cache WHERE id = ?`, [url], async (err) => { @@ -51,6 +51,7 @@ app.get('/', async (req, res) => { return; } res.contentType("application/json"); + res.header("cache", "stale - invalidated"); res.send(resp) console.log("old response (entry readded)"); }); @@ -58,7 +59,7 @@ app.get('/', async (req, res) => { insertStmt.finalize(); }); } else { - console.log("cache valid") + res.header("cache", "fresh"); res.contentType("application/json"); res.send(row.response); } @@ -73,7 +74,9 @@ app.get('/', async (req, res) => { return; } res.contentType("application/json"); + res.header("cache", "wasnt"); res.send(resp) + console.log("New entry added"); });