-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
40 lines (34 loc) · 1.2 KB
/
app.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
const ProxyChain = require('proxy-chain');
const appConfig = require("./config/app-config");
const ApiCaller = require("api-caller");
const apiCaller = new ApiCaller(1);
const server = new ProxyChain.Server({
port: 8000,
verbose: true,
prepareRequestFunction: async ({request, username, password, hostname, port, isHttp, connectionId}) => {
const country = getCountry(username);
let scrapperApiUrl = appConfig.endpoint + "?api_key=" + password + "&url=" + request.url;
if (country){
scrapperApiUrl = scrapperApiUrl + "&country_code=" + country;
}
const scraperApiResponse = await apiCaller.callGet(scrapperApiUrl, {});
return {
customResponseFunction: () => {
return {
statusCode: scraperApiResponse.statusCode,
body: scraperApiResponse.body,
};
},
};
},
});
function getCountry(username) {
if (username.indexOf("country") >= 0) {
const splitted = username.split("-");
return splitted[splitted.length - 1];
}
return false;
}
server.listen(() => {
console.log(`Proxy server is listening on port ${server.port}`);
});