no luck with sock proxies
This commit is contained in:
parent
a7cca4d4a1
commit
0eeb893d0f
5 changed files with 98 additions and 61 deletions
|
|
@ -35,6 +35,7 @@ export class ProxyManager {
|
|||
switch (proxy.protocol) {
|
||||
case 'socks4':
|
||||
case 'socks5':
|
||||
console.log(`Using SOCKS proxy: ${proxyUrl}`);
|
||||
return new SocksProxyAgent(proxyUrl);
|
||||
case 'http':
|
||||
return new HttpProxyAgent(proxyUrl);
|
||||
|
|
@ -48,29 +49,32 @@ export class ProxyManager {
|
|||
/**
|
||||
* Create Got instance with proxy configuration
|
||||
*/
|
||||
static createGotInstance(proxy: ProxyInfo) {
|
||||
static async createGotInstance(proxy: ProxyInfo): Promise<typeof got> {
|
||||
const agent = this.createGotAgent(proxy);
|
||||
|
||||
await new Promise(r => setTimeout(r, 2000));
|
||||
return got.extend({
|
||||
agent: {
|
||||
http: agent,
|
||||
https: agent
|
||||
},
|
||||
timeout: {
|
||||
request: 30000,
|
||||
connect: 10000
|
||||
},
|
||||
retry: {
|
||||
limit: 3,
|
||||
methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH']
|
||||
},
|
||||
throwHttpErrors: false // We'll handle errors ourselves
|
||||
});
|
||||
http2: false,
|
||||
agent: {
|
||||
http: agent,
|
||||
https: agent
|
||||
},
|
||||
timeout: {
|
||||
request: 30000,
|
||||
connect: 10000
|
||||
},
|
||||
retry: {
|
||||
limit: 3,
|
||||
methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH']
|
||||
},
|
||||
throwHttpErrors: false // We'll handle errors ourselves
|
||||
});
|
||||
}
|
||||
|
||||
private static buildProxyUrl(proxy: ProxyInfo): string {
|
||||
const { protocol, host, port, username, password } = proxy;
|
||||
|
||||
if( protocol.includes('socks') ) {
|
||||
return `socks5://${encodeURIComponent('me@bojancode.com')}:${encodeURIComponent('re$Pon7dipR')}@atlanta.us.socks.nordhold.net:1080`;
|
||||
}
|
||||
if (username && password) {
|
||||
return `${protocol}://${encodeURIComponent(username)}:${encodeURIComponent(password)}@${host}:${port}`;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue