如何通过http_proxy和no_proxy环境变量使用ProxyAgent

问题描述 投票:0回答:1

我正在研究如何使用 ProxyAgent 来启用 https_proxy 和 http_proxy 环境变量的功能,但我不太理解文档(https://www.npmjs.com/package/proxy-agent/v/6.4.0 )。 如果我实例化一个新的ProxyAgent,如何传入uri?会不会像这样

new ProxyAgent({uri:process.env.http_proxy})

文档说 ProxyAgent 将采用 ProxyAgentOptions 类型的选项参数,但我不确定 ProxyAgentOptions 应该是什么样子,以及它是否接受 uri 参数。

ProxyAgent 如何知道使用 http_proxy 或 https_proxy 变量?这是 ProxyAgent 处理的逻辑还是我必须自己实现该逻辑?对于 no_proxy 列表也是如此;这是 ProxyAgent 可以处理的事情吗?或者我必须自己实现 no_proxy 逻辑。询问是因为我找不到解释这一点的文档。

javascript security proxy environment-variables https-proxy-agent
1个回答
0
投票
const agent = new ProxyAgent({ host: "x.y.z.w", port: "xxxx", protocol: "http|https"});
© www.soinside.com 2019 - 2024. All rights reserved.