From a06bd771ff4ea43841edb8cba97df21258a9912b Mon Sep 17 00:00:00 2001 From: CloudburstSys Date: Tue, 24 May 2022 11:15:04 +0100 Subject: Create /api/servers endpoint --- index.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'index.js') diff --git a/index.js b/index.js index 3108183..797791a 100644 --- a/index.js +++ b/index.js @@ -6,15 +6,23 @@ const app = express(); app.use(express.static('public')); app.set("view engine", "ejs"); -app.get('/', function (req, res) { +app.get('/', (req, res) => { res.render("index"); -}) +}); + +// API +var serverCache = {}; + +app.get("/api/servers", (req, res) => { + res.json(serverCache); +}); const refresh = require('./refresh'); setInterval(() => { console.log("Running refresh..."); - refresh().then(() => { + refresh().then(data => { console.log("Refresh done!"); + serverCache = data; }); }, 300000); @@ -24,7 +32,8 @@ const server = app.listen(8099, function () { console.log("Vapor Trail server listening at http://%s:%s", host, port) console.log("Running refresh..."); - refresh().then(() => { + refresh().then(data => { console.log("Refresh done!"); + serverCache = data; }); }) \ No newline at end of file -- cgit