| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
|
|
| import { ProxyAgent } from 'undici';
|
| import { getConfig } from './config.js';
|
|
|
| let cachedAgent: ProxyAgent | undefined;
|
|
|
| |
| |
| |
|
|
| export function getProxyDispatcher(): ProxyAgent | undefined {
|
| const config = getConfig();
|
| const proxyUrl = config.proxy;
|
|
|
| if (!proxyUrl) return undefined;
|
|
|
| if (!cachedAgent) {
|
| console.log(`[Proxy] 使用代理: ${proxyUrl}`);
|
| cachedAgent = new ProxyAgent(proxyUrl);
|
| }
|
|
|
| return cachedAgent;
|
| }
|
|
|
| |
| |
| |
|
|
| export function getProxyFetchOptions(): Record<string, unknown> {
|
| const dispatcher = getProxyDispatcher();
|
| return dispatcher ? { dispatcher } : {};
|
| }
|
|
|