2020-09-25 20:11:19 +00:00
|
|
|
// async https wrapper
|
|
|
|
|
|
|
|
const https = require('https');
|
|
|
|
|
|
|
|
module.exports = (url) => new Promise((resolve, reject) => {
|
|
|
|
const headers = {};
|
|
|
|
headers['user-agent'] = '(WeatherStar 4000+ data generator, ws4000@netbymatt.com)';
|
|
|
|
|
|
|
|
https.get(url, {
|
|
|
|
headers,
|
2022-11-22 20:17:04 +00:00
|
|
|
}, (res) => {
|
2020-09-25 20:11:19 +00:00
|
|
|
if (res.statusCode === 200) {
|
|
|
|
const buffers = [];
|
2022-11-22 20:17:04 +00:00
|
|
|
res.on('data', (data) => buffers.push(data));
|
2020-09-25 20:11:19 +00:00
|
|
|
res.on('end', () => resolve(Buffer.concat(buffers).toString()));
|
|
|
|
} else {
|
|
|
|
console.log(res);
|
|
|
|
reject(new Error(`Unable to get: ${url}`));
|
|
|
|
}
|
2022-11-22 20:17:04 +00:00
|
|
|
}).on('error', (e) => {
|
2020-09-25 20:11:19 +00:00
|
|
|
console.log(e);
|
|
|
|
reject(e);
|
|
|
|
});
|
2022-11-22 20:17:04 +00:00
|
|
|
});
|