-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrequest.js
More file actions
34 lines (30 loc) · 775 Bytes
/
request.js
File metadata and controls
34 lines (30 loc) · 775 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const https = require('https');
const fakeUserAgent = require('fake-useragent');
module.exports = function request(path, cb = (rs, err) => ({ rs, err })) {
const req = https.request({
hostname: 'api4.temp-mail.org',
port: 443,
path,
method: 'GET',
// Adding fake user agent string to bypass cloudflare
headers: {
'user-agent': fakeUserAgent(),
},
}, (res) => {
let d = '';
res.on('data', (chunk) => {
d += chunk;
});
res.on('end', () => {
d = d.toString();
try {
if (typeof d !== 'object') d = JSON.parse(d);
} catch (e) {
return cb(d, new Error('Can\'t parse server response'));
}
return cb(d, null);
});
});
req.on('error', (e) => cb(e));
req.end();
};