Skip to content

Commit

Permalink
replace request with node-fetch LukeSkywalker92#37
Browse files Browse the repository at this point in the history
 fixing request is deprecated LukeSkywalker92#37
  • Loading branch information
codac authored Jan 5, 2022
1 parent f3aea04 commit 47ef90d
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions node_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/

var NodeHelper = require('node_helper');
var request = require('request');
const fetch = require('node-fetch');

module.exports = NodeHelper.create({
start: function () {
Expand Down Expand Up @@ -54,16 +54,15 @@ module.exports = NodeHelper.create({
var warnurl = 'https://maps.dwd.de/geoserver/dwd/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=dwd:Warnungen_Gemeinden&outputFormat=application%2Fjson&CQL_FILTER=' + regionFilter + severityStr;
// console.error(warnurl);

var requests = 2;

var requests = 2;
//get name
request({
url: nameurl,
fetch(nameurl, {
method: 'GET'
}, function (error, response, body) {
var result = JSON.parse(body);
if (result.totalFeatures == 1) {
communityData = result.features[0];
}).then(res => res.json()
).then(json => {
if (json.totalFeatures == 1) {
communityData = json.features[0];
}
if (--requests == 0) {
if (region.reg)
Expand All @@ -72,18 +71,15 @@ module.exports = NodeHelper.create({
callback(self, warningData, region.cellid, communityData);
}
});

//get warnings
request({
url: warnurl,
fetch(warnurl, {
method: 'GET'
}, function (error, response, body) {

var result = JSON.parse(body);

if (result.totalFeatures > 0) {
for (var i = 0; i < result.totalFeatures; i++) {
warningData.push(result.features[i]);
}).then(res => res.json()
).then(json => {
if (json.totalFeatures > 0) {
for (var i = 0; i < json.totalFeatures; i++) {
warningData.push(json.features[i]);
}
}
if (--requests == 0) {
Expand Down

0 comments on commit 47ef90d

Please sign in to comment.