fix the problem that axios don't use the http proxy #21199

This commit is contained in:
Lerr1uqs 2025-11-08 20:13:05 +08:00
parent 9a54024b4a
commit 496a43e02b

View File

@ -268,6 +268,16 @@ export async function invokeAxios(
axiosConfig: AxiosRequestConfig,
authOptions: IRequestOptions['auth'] = {},
) {
// axios not apply the http.globalAgent, need set it manually
const url = process.env.HTTP_PROXY ?? process.env.HTTPS_PROXY ?? process.env.ALL_PROXY;
if (url) {
const parsedUrl = new URL(url);
axiosConfig.proxy = {
host: parsedUrl.hostname,
port: parseInt(parsedUrl.port) || (parsedUrl.protocol === 'https:' ? 443 : 80),
protocol: parsedUrl.protocol.replace(':', ''),
};
}
try {
return await axios(axiosConfig);
} catch (error) {