fix: 添加 https-proxy-agent 依赖,解决代理DNS解析问题
This commit is contained in:
+2
-1
@@ -67,6 +67,7 @@
|
||||
"vite": "^5.4.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"sql.js": "^1.11.0"
|
||||
"sql.js": "^1.11.0",
|
||||
"https-proxy-agent": "^7.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,24 +12,27 @@ import { getWorkspaceDir } from './workspace.js';
|
||||
|
||||
// ── 代理支持 ──
|
||||
let _proxyUrl = '';
|
||||
let _proxyAgent: any = null;
|
||||
|
||||
function getProxyAgent(): any {
|
||||
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 {
|
||||
const { ProxyAgent } = require('undici');
|
||||
_proxyAgent = new ProxyAgent(_proxyUrl);
|
||||
return _proxyAgent;
|
||||
return new ProxyAgent(_proxyUrl);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 设置 HTTP 代理(供 IPC 调用) */
|
||||
export function setProxyUrl(url: string): void {
|
||||
_proxyUrl = url;
|
||||
_proxyAgent = null; // 重建 agent
|
||||
}
|
||||
|
||||
/** 当前工具命令进程(用于用户手动终止) */
|
||||
|
||||
Reference in New Issue
Block a user