mirror of
https://github.com/anatolykopyl/status.git
synced 2026-03-26 12:54:46 +00:00
Initial commit
This commit is contained in:
25
server/httpsReq.js
Normal file
25
server/httpsReq.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import https from "https";
|
||||
|
||||
export function httpsReq(url) {
|
||||
return new Promise(resolve => {
|
||||
https.get(url, (res) => {
|
||||
res.setEncoding('utf8');
|
||||
let data = '';
|
||||
|
||||
res.on('data', chunk => {
|
||||
data += chunk;
|
||||
});
|
||||
|
||||
res.on('end', () => {
|
||||
try {
|
||||
let jsonObj = JSON.parse(data);
|
||||
resolve(jsonObj);
|
||||
} catch (e) {
|
||||
res.status(400).send('Invalid JSON string');
|
||||
}
|
||||
});
|
||||
}).on('error', err => {
|
||||
console.log('Error: ' + err.message);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user