block_hacks
block_hacks•9mo ago

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

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.
7 Replies
Deno AI Helper
Deno AI Helper•9mo ago
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"
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. 🦕
block_hacks
block_hacks•9mo ago
I am using npm:google-trends-api. I am not making any fetch requests myself. How can I set proxy so even my library requests under the hood use proxy to make requests
Deno AI Helper
Deno AI Helper•9mo ago
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"
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. 🦕
raunioroo
raunioroo•9mo ago
does setting proxy config as environment variable somehow not work for you? i think it should exactly make any third party library fetch calls to also use the proxy
block_hacks
block_hacks•9mo ago
doesn't work for me at all tried on Ubuntu, Kali and Windows 11
raunioroo
raunioroo•9mo ago
are you sure the env vars are set correctly so that Deno seems them? Does
const env = Deno.env.toObject();
console.log("env:", env);
const env = Deno.env.toObject();
console.log("env:", env);
print them out? If yes, then idk what the issue could be
block_hacks
block_hacks•9mo ago
I did explicitly printed them out as I mentioned, did it on Linux & Windows