const path = require('path'); const axios = require('axios'); const express = require('express'); const NodeCache = require("node-cache"); const cache = new NodeCache(); const app = express(); // serve files inside the public folder from / app.use('/', express.static(path.join(__dirname, 'public'))); async function getCached(key, ttl, callback) { // find data from cache let data = cache.get(key); // update cache if(!data){ data = await callback(); cache.set(key, data, ttl); } // get expiration time in seconds const cacheTtl = cache.getTtl(key); const expiresIn = cacheTtl != null ? Math.ceil((cacheTtl - Date.now()) / 1000) : 0; // return data return [ data, expiresIn ]; } app.get('/', async (req, res) => { res.sendFile(path.join(__dirname, 'public/index.html')); }); app.get('/api', async (req, res) => { const links = [ { "path": "/api", "description": "This page", }, { "path": "/api/v1/nodes", "description": "Meshtastic nodes in JSON format.", }, ]; const html = links.map((link) => { return `