diff --git a/index.js b/index.js index b785332..faa44f2 100644 --- a/index.js +++ b/index.js @@ -26,11 +26,19 @@ let settings = { arrayMax }; +let cache = {}; +let cacheDate = 0; + if (mode == 'cli') { main(settings); } else if (mode == 'site') { const app = e(); app.get('/top', async (req, res) => { + if ((new Date) - cacheDate < 1000*10) { + res.send(cache); + return; + } + let json = await fetch("https://nbg.dervland.net/api/followjson.php"); try { json = await json.json(); @@ -70,7 +78,10 @@ if (mode == 'cli') { dat2[d[0]] = d[1] * 100 + "%"; } - res.send(JSON.stringify(dat2)) + cache = JSON.stringify(dat2); + cacheDate = +(new Date); + + res.send(cache) }) app.listen(port);