#How to set proxy to overall all requests coming from application?

1 messages · Page 1 of 1 (latest)

hazy relic
#

In Node JS, we can import https and set https.proxy = "proxyDetails
However, I couldn't find a way to do so in Deno. I even tried to run node js child_process app with proxy over Deno, still not possible.

slim tundraBOT
#

In Deno, proxy configuration is read from environmental variables: HTTP_PROXY, HTTPS_PROXY and NO_PROXY. According to the documentation, if these environment variables are not found, Deno falls back to reading proxies from the registry in the case of Windows.

Here's how you can set these environment variables:

  1. HTTP_PROXY and HTTPS_PROXY: These variables hold the URL of the proxy server. The format is http://<host>:<port> for HTTP_PROXY and https://<host>:<port> for HTTPS_PROXY.

  2. NO_PROXY: This variable should contain a comma-separated list of domain extensions proxy should not be used for.

Please note that these environment variables need to be set in the environment where the Deno process runs. How to set these variables depends on your operating system and shell.

For example, in a Unix-based system with a bash-like shell, you can set these variables as follows:

export HTTP_PROXY=http://proxy.example.com:8080
export HTTPS_PROXY=https://proxy.example.com:8080
export NO_PROXY=".example.com,.deno.land"

Then, you can run your Deno program in the same shell session, and it will pick up these proxy settings.

Remember, this is a process-level setting and will affect all fetch and module download requests made by the Deno process.

If you want to set the proxy for a specific fetch request, you can do so by creating a custom HTTP agent with the proxy settings and passing it in the options of the fetch request. However, this feature is not currently supported in Deno according to the documentation. 🦕

hazy relic
slim tundraBOT
#

According to the documentation, Deno reads proxy configuration from environment variables: HTTP_PROXY, HTTPS_PROXY, and NO_PROXY. If these environment variables are not found, Deno falls back to reading proxies from the registry in the case of Windows.

So, if the npm:google-trends-api library you are using makes HTTP or HTTPS requests under the hood, these requests should respect the proxy settings defined in these environment variables.

Here's how you can set these environment variables:

  1. HTTP_PROXY and HTTPS_PROXY: These variables hold the URL of the proxy server. The format is http://<host>:<port> for HTTP_PROXY and https://<host>:<port> for HTTPS_PROXY.

  2. NO_PROXY: This variable should contain a comma-separated list of domain extensions proxy should not be used for.

Please note that these environment variables need to be set in the environment where the Deno process runs. How to set these variables depends on your operating system and shell.

For example, in a Unix-based system with a bash-like shell, you can set these variables as follows:

export HTTP_PROXY=http://proxy.example.com:8080
export HTTPS_PROXY=https://proxy.example.com:8080
export NO_PROXY=".example.com,.deno.land"

Then, you can run your Deno program in the same shell session, and it will pick up these proxy settings.

Remember, this is a process-level setting and will affect all fetch and module download requests made by the Deno process.

If you want to set the proxy for a specific fetch request, you can do so by creating a custom HTTP agent with the proxy settings and passing it in the options of the fetch request. However, this feature is not currently supported in Deno according to the documentation. 🦕

vale arch
hazy relic
vale arch
#

are you sure the env vars are set correctly so that Deno seems them? Does const env = Deno.env.toObject(); console.log("env:", env); print them out? If yes, then idk what the issue could be

hazy relic