const createAxiosInstance = (proxyUrl) => {
if (proxyUrl) {
const proxyParts = proxyUrl.match(/^(https?):\/\/(?:(\w+):(\w+)@)?([^:\/]+)(?::(\d+))?$/);
log.info(`proxy:: ${proxyParts}`);
const agent = new HttpsProxyAgent(proxyUrl);
if (proxyParts) {
const [fullMatch, protocol, user, password, host, port] = proxyParts;
log.info(`host: ${host},port:${port}`);
return axios.create({
baseURL: 'https://api.plaza.finance/',
headers,
proxy: {
protocol: 'http',
host: host,
port: parseInt(port, 10),
//auth: {
// username: user,
// password: password,
//},
httpsAgent: agent, // 使用 HTTPS 代理
},
});
} else {
throw new Error('Invalid proxy URL format');
}
} else {
return axios.create({
baseURL: 'https://api.plaza.finance/',
headers,
});
}
};
axios.create 使用http代理
最新推荐文章于 2025-03-10 21:21:24 发布