fix: 添加 https-proxy-agent 依赖,解决代理DNS解析问题

This commit is contained in:
thzxx
2026-06-10 16:00:46 +08:00
parent 53dec75528
commit 25809c1532
2 changed files with 12 additions and 8 deletions
+2 -1
View File
@@ -67,6 +67,7 @@
"vite": "^5.4.0" "vite": "^5.4.0"
}, },
"dependencies": { "dependencies": {
"sql.js": "^1.11.0" "sql.js": "^1.11.0",
"https-proxy-agent": "^7.0.0"
} }
} }
+8 -5
View File
@@ -12,24 +12,27 @@ import { getWorkspaceDir } from './workspace.js';
// ── 代理支持 ── // ── 代理支持 ──
let _proxyUrl = ''; let _proxyUrl = '';
let _proxyAgent: any = null;
function getProxyAgent(): any { function getProxyAgent(): any {
if (!_proxyUrl) return null; if (!_proxyUrl) return null;
if (_proxyAgent) return _proxyAgent; try {
const url = new URL(_proxyUrl);
const { HttpsProxyAgent } = require('https-proxy-agent');
return new HttpsProxyAgent(url);
} catch {
// https-proxy-agent 不可用,尝试 undici
try { try {
const { ProxyAgent } = require('undici'); const { ProxyAgent } = require('undici');
_proxyAgent = new ProxyAgent(_proxyUrl); return new ProxyAgent(_proxyUrl);
return _proxyAgent;
} catch { } catch {
return null; return null;
} }
} }
}
/** 设置 HTTP 代理(供 IPC 调用) */ /** 设置 HTTP 代理(供 IPC 调用) */
export function setProxyUrl(url: string): void { export function setProxyUrl(url: string): void {
_proxyUrl = url; _proxyUrl = url;
_proxyAgent = null; // 重建 agent
} }
/** 当前工具命令进程(用于用户手动终止) */ /** 当前工具命令进程(用于用户手动终止) */