MMM-MyCovid19/node_helper.js
Sebastian Mark 741d2d1838 FIX: XMLHttpRequest blocked by CORS policy
* move http query to `node_helper`
* replace `XMLHttpRequest` by `node-fetch`
* implement SocketNotifications
2021-09-08 09:43:25 +02:00

27 lines
829 B
JavaScript

var NodeHelper = require("node_helper");
const fetch = require("node-fetch");
var data_url = "https://rp-online.de/app/interaktiv_server/data/rki_nrw_mapped.json.php";
var cases = {}
module.exports = NodeHelper.create({
socketNotificationReceived: function (notification, region) {
// get and parse json data from source
res = fetch(data_url)
.then(response=>response.json())
.then(data=>{
// extract data
cases.new7 = data[region]["last_7"];
cases.new7_100k = data[region]["last_7_100000"];
cases.active = data[region]["active"];
cases.total = data[region]["cases"];
cases.death = data[region]["tot"];
cases.cured = data[region]["gesund"];
cases.ts = data[region]["date"];
// send data back to module
this.sendSocketNotification("{{MODULE_NAME}}-set_cases", cases)
})
},
});