-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-call.js
51 lines (49 loc) · 1.56 KB
/
test-call.js
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const request = require("request");
function GetUrlFromJSWeeklyLinkId(linkId) {
const linkurl = `https://javascriptweekly.com/link/${linkId}`;
console.log("Rquesting linkurl", linkurl);
return new Promise(function(resolve, reject) {
request(
{
method: "GET",
uri: linkurl,
followRedirect: false,
headers: {
Host: "javascriptweekly.com",
Connection: "keep-alive",
Pragma: "no-cache",
"Cache-Control": "no-cache",
"Upgrade-Insecure-Requests": "1",
"User-Agent":
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36",
Accept:
"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-GB,en-US;q=0.9,en;q=0.8"
}
},
(err, res, body) => {
if (err) {
console.error(`Error - ${linkId}`, err);
reject({ err });
}
console.log("res.headers", res.headers);
console.log("statusCode:", res && res.statusCode);
console.log("body", body);
resolve({});
}
);
});
}
async function runMain(params) {
//Main function to run after DB.
try {
//await Link.sync({ force: false });
console.log("Caling 1 xhr call...");
var data = await GetUrlFromJSWeeklyLinkId(134);
var data = await GetUrlFromJSWeeklyLinkId(13400);
} catch (error) {
console.error(error);
}
}
runMain();