test
This commit is contained in:
parent
0937651f67
commit
117ff56d1e
5 changed files with 11 additions and 14 deletions
|
|
@ -40,7 +40,7 @@ async function demonstrateProxyService() {
|
||||||
console.log('Working proxy found:', {
|
console.log('Working proxy found:', {
|
||||||
host: workingProxy.host,
|
host: workingProxy.host,
|
||||||
port: workingProxy.port,
|
port: workingProxy.port,
|
||||||
type: workingProxy.type
|
protocol: workingProxy.protocol
|
||||||
});
|
});
|
||||||
|
|
||||||
// 7. Test the proxy
|
// 7. Test the proxy
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { createLogger } from '@stock-bot/logger';
|
import { createLogger } from '@stock-bot/logger';
|
||||||
import { createCache } from '@stock-bot/cache';
|
import createCache, { type CacheProvider } from '@stock-bot/cache';
|
||||||
import { HttpClient, ProxyConfig } from '@stock-bot/http-client';
|
import { HttpClient, ProxyConfig } from '@stock-bot/http-client';
|
||||||
import type { CacheProvider } from '@stock-bot/cache';
|
|
||||||
import type { Logger as PinoLogger } from 'pino';
|
import type { Logger as PinoLogger } from 'pino';
|
||||||
|
|
||||||
export interface ProxySource {
|
export interface ProxySource {
|
||||||
|
|
@ -163,7 +162,7 @@ export class ProxyService {
|
||||||
this.parseHttpProxyList(response.data);
|
this.parseHttpProxyList(response.data);
|
||||||
|
|
||||||
return proxies.map(proxy => ({
|
return proxies.map(proxy => ({
|
||||||
type: 'http', // Fixed type to match ProxyConfig interface
|
protocol: source.protocol,
|
||||||
host: proxy.host,
|
host: proxy.host,
|
||||||
port: proxy.port,
|
port: proxy.port,
|
||||||
username: proxy.username,
|
username: proxy.username,
|
||||||
|
|
@ -193,7 +192,7 @@ export class ProxyService {
|
||||||
const [host, port] = trimmed.split(':');
|
const [host, port] = trimmed.split(':');
|
||||||
if (host && port && this.isValidIP(host) && this.isValidPort(port)) {
|
if (host && port && this.isValidIP(host) && this.isValidPort(port)) {
|
||||||
proxies.push({
|
proxies.push({
|
||||||
type: 'http',
|
protocol: 'http',
|
||||||
host: host.trim(),
|
host: host.trim(),
|
||||||
port: parseInt(port.trim())
|
port: parseInt(port.trim())
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,6 @@ import type {
|
||||||
HttpClientConfig,
|
HttpClientConfig,
|
||||||
RequestConfig,
|
RequestConfig,
|
||||||
HttpResponse,
|
HttpResponse,
|
||||||
HttpMethod,
|
|
||||||
ProxyConfig,
|
|
||||||
} from './types.js';
|
} from './types.js';
|
||||||
import {
|
import {
|
||||||
HttpError,
|
HttpError,
|
||||||
|
|
|
||||||
|
|
@ -8,17 +8,17 @@ export class ProxyManager {
|
||||||
* Create appropriate proxy agent based on configuration
|
* Create appropriate proxy agent based on configuration
|
||||||
*/
|
*/
|
||||||
static createAgent(proxy: ProxyConfig): HttpsProxyAgent<string> | SocksProxyAgent {
|
static createAgent(proxy: ProxyConfig): HttpsProxyAgent<string> | SocksProxyAgent {
|
||||||
const { type, host, port, username, password } = proxy;
|
const { protocol, host, port, username, password } = proxy;
|
||||||
|
|
||||||
let proxyUrl: string;
|
let proxyUrl: string;
|
||||||
|
|
||||||
if (username && password) {
|
if (username && password) {
|
||||||
proxyUrl = `${type}://${encodeURIComponent(username)}:${encodeURIComponent(password)}@${host}:${port}`;
|
proxyUrl = `${protocol}://${encodeURIComponent(username)}:${encodeURIComponent(password)}@${host}:${port}`;
|
||||||
} else {
|
} else {
|
||||||
proxyUrl = `${type}://${host}:${port}`;
|
proxyUrl = `${protocol}://${host}:${port}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (type) {
|
switch (protocol) {
|
||||||
case 'http':
|
case 'http':
|
||||||
case 'https':
|
case 'https':
|
||||||
return new HttpsProxyAgent(proxyUrl);
|
return new HttpsProxyAgent(proxyUrl);
|
||||||
|
|
@ -26,7 +26,7 @@ export class ProxyManager {
|
||||||
case 'socks5':
|
case 'socks5':
|
||||||
return new SocksProxyAgent(proxyUrl);
|
return new SocksProxyAgent(proxyUrl);
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unsupported proxy type: ${type}`);
|
throw new Error(`Unsupported proxy protocol: ${protocol}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' |
|
||||||
|
|
||||||
// Proxy configuration
|
// Proxy configuration
|
||||||
export interface ProxyConfig {
|
export interface ProxyConfig {
|
||||||
type: 'http' | 'https' | 'socks4' | 'socks5';
|
protocol: 'http' | 'https' | 'socks4' | 'socks5';
|
||||||
host: string;
|
host: string;
|
||||||
port: number;
|
port: number;
|
||||||
username?: string;
|
username?: string;
|
||||||
|
|
@ -120,7 +120,7 @@ export function validateProxyConfig(config: unknown): ProxyConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: proxy.type as ProxyConfig['type'],
|
protocol: proxy.protocol as ProxyConfig['protocol'],
|
||||||
host: proxy.host.trim(),
|
host: proxy.host.trim(),
|
||||||
port: proxy.port,
|
port: proxy.port,
|
||||||
username: proxy.username as string | undefined,
|
username: proxy.username as string | undefined,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue