Skip to content
This repository was archived by the owner on Oct 4, 2024. It is now read-only.

feat: Add proxy settings - #1067

Open
xiangxn wants to merge 2 commits into
near:masterfrom
xiangxn:master
Open

feat: Add proxy settings#1067
xiangxn wants to merge 2 commits into
near:masterfrom
xiangxn:master

Conversation

@xiangxn

@xiangxn xiangxn commented Sep 28, 2023

Copy link
Copy Markdown

you only need to set the environment variable:
export GLOBAL_AGENT_HTTP_PROXY="http://127.0.0.1:8001"

View in detail: https://github.com/gajus/global-agent

@think-in-universe

Copy link
Copy Markdown
Member

This is great! This fix makes near-cli usable for developers who need http(s) proxies to visit NEAR RPC and helper services.

Can you make some enhancements to support HTTP_PROXY, HTTPS_PROXY and NO_PROXY environment variables?

@xiangxn

xiangxn commented Sep 28, 2023

Copy link
Copy Markdown
Author

These are all supported, please check for details: https://github.com/gajus/global-agent

@think-in-universe

Copy link
Copy Markdown
Member

I mean after import global agent, you can configure the global agent environment variables, so near-cli acts more like a normal process that respects the environment variables HTTP_PROXY, HTTPS_PROXY and NO_PROXY.

function setProxies() {
  const http_proxy = process.env.http_proxy || process.env.HTTP_PROXY;
  if (http_proxy) {
    global.GLOBAL_AGENT.HTTP_PROXY = http_proxy;
  }

  const https_proxy = process.env.https_proxy || process.env.HTTPS_PROXY;
  if (https_proxy) {
    global.GLOBAL_AGENT.HTTPS_PROXY = https_proxy;
  }

  const no_proxy = process.env.no_proxy || process.env.NO_PROXY;
  if (no_proxy) {
    global.GLOBAL_AGENT.NO_PROXY = no_proxy;
  }
}

@xiangxn

xiangxn commented Oct 5, 2023

Copy link
Copy Markdown
Author

I mean after import global agent, you can configure the global agent environment variables, so near-cli acts more like a normal process that respects the environment variables HTTP_PROXY, HTTPS_PROXY and NO_PROXY.

function setProxies() {
  const http_proxy = process.env.http_proxy || process.env.HTTP_PROXY;
  if (http_proxy) {
    global.GLOBAL_AGENT.HTTP_PROXY = http_proxy;
  }

  const https_proxy = process.env.https_proxy || process.env.HTTPS_PROXY;
  if (https_proxy) {
    global.GLOBAL_AGENT.HTTPS_PROXY = https_proxy;
  }

  const no_proxy = process.env.no_proxy || process.env.NO_PROXY;
  if (no_proxy) {
    global.GLOBAL_AGENT.NO_PROXY = no_proxy;
  }
}

Updated to support these environment variables by default.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants