Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support HTTP_PROXY and NO_PROXY environment variables #1168

Open
thda opened this issue Mar 29, 2024 · 9 comments
Open

Support HTTP_PROXY and NO_PROXY environment variables #1168

thda opened this issue Mar 29, 2024 · 9 comments
Labels
enhancement New feature or request

Comments

@thda
Copy link

thda commented Mar 29, 2024

Hi,

building the example pages fails behind a corporate proxy.

Fetching d3-dsv fails and running npm add d3-dsv does not fix.

I cannot post the stack trace (corporate policies) but it looks like fetch uses undici which does not handle https_proxy and no_proxy env variables.

Thanks

@thda thda added the bug Something isn’t working label Mar 29, 2024
@mbostock mbostock added enhancement New feature or request and removed bug Something isn’t working labels Mar 29, 2024
@mbostock mbostock changed the title Cannot build behind corporate proxy Support HTTP_PROXY and NO_PROXY environment variables Mar 29, 2024
@mbostock
Copy link
Member

Ref. nodejs/undici#1650
Ref. nodejs/node#8381

@thda
Copy link
Author

thda commented Mar 30, 2024

Thanks for acknowledging the feature request.

In the meantime is it possible to bypass the dynamic install done using jsdelivr and rely only on node_modules ?

Some corporate environments provide vetted mirrors of npm and disallow the use of proxys in build environments.

@Fil
Copy link
Contributor

Fil commented Mar 30, 2024

In the meantime is it possible to bypass the dynamic install done using jsdelivr and rely only on node_modules ?

The next release will integrate this feature that was just merged this week #1156

@mbostock
Copy link
Member

mbostock commented Mar 30, 2024

Also, even if you use node_modules for explicit imports, you would have to fastidiously avoid using any implicit imports, as all implicit imports are npm: imports that are downloaded from jsDelivr.

It should be possible for us to add a proxy config option, and then respect that option when fetching from jsDelivr. I’m looking into it now. The main difficulty is the plumbing (we make the request within populateNpmCache and we don’t have access to the config there, but we could pass it in).

@mbostock
Copy link
Member

mbostock commented Mar 30, 2024

You could try installing Undici and adding the following to your observablehq.config.js:

import {ProxyAgent, setGlobalDispatcher} from "undici";

const proxyAgent = new ProxyAgent({uri: process.env.https_proxy});
setGlobalDispatcher(proxyAgent);

Or, if your proxy has a username and password and uses basic auth:

import {ProxyAgent, setGlobalDispatcher} from "undici";

const proxyUrl = new URL(process.env.https_proxy);
const token = `Basic ${btoa(`${proxyUrl.username}:${proxyUrl.password}`)}`;
const proxyAgent = new ProxyAgent({uri: proxyUrl.protocol + proxyUrl.host, token});
setGlobalDispatcher(proxyAgent);

This would require you to set the https_proxy environment variable and pass it through to the observable command, say using dotenv. You could also just hard-code the process.env.https_proxy with your proxy to see if it works.

@muuankarski
Copy link

Install undici and adding the content of upper code block to observablehq.config.js with hard coded proxy address did the trick and I can finally use versions above 1.0.0!

@thda
Copy link
Author

thda commented Apr 3, 2024

Thanks, the provided code fixed it for me too. I’ll try the implicit import route too once released.

@gdelfino
Copy link

gdelfino commented May 8, 2024

You could try installing Undici and adding the following to your observablehq.config.js:

import {ProxyAgent, setGlobalDispatcher} from "undici";

const proxyAgent = new ProxyAgent({uri: process.env.https_proxy});
setGlobalDispatcher(proxyAgent);

This worked for me after some changes. In my case, there is not only a corporate proxy but also a custom CA. For now I just disabled the check, but ideally I should somehow configure it to use my custom CA certificate:

import {ProxyAgent, setGlobalDispatcher} from "undici";

const proxyAgent = new ProxyAgent( {uri: process.env.https_proxy, 
                                    requestTls:{rejectUnauthorized:false}} );
setGlobalDispatcher(proxyAgent);

@eosfor
Copy link

eosfor commented Oct 29, 2024

in case of ZScaler or any other thing like that the ProxyAgent might not work, as it is not a real proxy. So wat you can also do is to set rejectUnauthorized: false in observablehq.config.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants