From 12bf6c165373d75d925d81202ef358eb0ab5d392 Mon Sep 17 00:00:00 2001 From: Gilles Hamel Date: Mon, 27 Apr 2020 11:18:09 +0200 Subject: [PATCH] Enable reloading data.json To reload data, post the url /reload. ie: curl -X POST http://localhost:3003/reload --- routes/index.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/routes/index.js b/routes/index.js index e044d9b..6f44022 100644 --- a/routes/index.js +++ b/routes/index.js @@ -37,6 +37,24 @@ router.get('/', function(req, res, next) { res.render('index', { title: 'Grafana SimpleJSON Value Mapper' }); }); +/** + * Reload data.json + */ +router.post('/reload', isAuthorized, function(req, res, next) { + + for (var k in require.cache) { + + if (! k.match(/\/server\/data.json$/)) continue; + + delete require.cache[k]; + break; + } + + data = require('../server/data.json'); + res.end(); + return; +}); + /** * This is the API endpoint that Grafana Simple JSON Datasources uses for metrics and template variables. */