mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 01:00:34 +08:00
36 lines
737 B
JavaScript
36 lines
737 B
JavaScript
const https = require('https');
|
|
|
|
exports.simpleGet = {
|
|
https(hostname, path) {
|
|
const requestOpt = hostname instanceof URL ? hostname : {
|
|
hostname,
|
|
path,
|
|
method: 'GET',
|
|
};
|
|
|
|
return new Promise((resolve, reject) => {
|
|
const req = https.request(
|
|
requestOpt,
|
|
(res) => {
|
|
const body = [];
|
|
res.on('data', (chunk) => {
|
|
body.push(chunk);
|
|
});
|
|
res.on('end', () => {
|
|
try {
|
|
resolve(String(Buffer.concat(body)));
|
|
} catch (e) {
|
|
reject(e);
|
|
}
|
|
});
|
|
req.on('error', (err) => {
|
|
reject(err);
|
|
});
|
|
}
|
|
);
|
|
|
|
req.end();
|
|
});
|
|
}
|
|
}
|