Skip to content

Commit

Permalink
Add proxy agent for node fetch
Browse files Browse the repository at this point in the history
Signed-off-by: Junze Wu <[email protected]>
  • Loading branch information
jnzw committed Dec 31, 2024
1 parent 8687011 commit c0e0d81
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
16 changes: 15 additions & 1 deletion js/node/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion js/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"version": "1.21.0",
"dependencies": {
"onnxruntime-common": "file:../common",
"tar": "^7.0.1"
"tar": "^7.0.1",
"undici": "^6.21.0"
},
"scripts": {
"postinstall": "node ./script/install",
Expand Down
7 changes: 6 additions & 1 deletion js/node/script/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const path = require('path');
const tar = require('tar');
const { execFileSync } = require('child_process');
const { Readable } = require('stream');
const { ProxyAgent } = require('undici');

// commandline flag:
// --onnxruntime-node-install-cuda Force install the CUDA EP binaries. Try to detect the CUDA version.
Expand Down Expand Up @@ -79,8 +80,12 @@ To use ONNX Runtime Node.js binding with CUDA v11 support, please follow the man
ORT_VERSION
}.tgz`,
}[INSTALL_CUDA_FLAG || tryGetCudaVersion()];

const proxyUrl = process.env.HTTPS_PROXY || process.env.HTTP_PROXY;
const proxyAgent = new ProxyAgent(proxyUrl);

console.log(`Downloading "${artifactUrl}"...`);
fetch(artifactUrl).then((res) => {
fetch(artifactUrl, { dispatcher: proxyAgent }).then((res) => {
if (!res.ok) {
throw new Error(`Failed to download the binaries: ${res.status} ${res.statusText}.
Expand Down

0 comments on commit c0e0d81

Please sign in to comment.