29 lines
908 B
JavaScript
29 lines
908 B
JavaScript
const axios = require('axios').default
|
|
const SocksProxyAgent = require('socks-proxy-agent');
|
|
const HttpsProxyAgent = require('https-proxy-agent');
|
|
|
|
const socksProxyOptions = `socks5://114.103.105.105:4216`; // your sock5 host and port;
|
|
const httpsProxyOptions = 'https://92.119.222.1:8080';
|
|
|
|
const socksAgent = new SocksProxyAgent(socksProxyOptions);
|
|
const httpAgent = new HttpsProxyAgent(httpsProxyOptions);
|
|
|
|
axios.interceptors.request.use( x => {
|
|
// to avoid overwriting if another interceptor
|
|
// already defined the same object (meta)
|
|
x.meta = x.meta || {}
|
|
x.meta.requestStartedAt = new Date().getTime();
|
|
return x;
|
|
});
|
|
|
|
axios.interceptors.response.use(x => {
|
|
x.responseTime = new Date().getTime() - x.config.meta.requestStartedAt;
|
|
return x;
|
|
});
|
|
|
|
axios({
|
|
httpsAgent: socksAgent,
|
|
url:'https://api.ipify.org/?format=json'
|
|
}).then(r => {
|
|
console.log(r.responseTime);
|
|
}) |