Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"commander": "^14.0.3",
"js-yaml": "^4.1.0",
"turndown": "^7.2.2",
"undici": "^7.24.5",
"ws": "^8.18.0"
},
"devDependencies": {
Expand Down
16 changes: 13 additions & 3 deletions src/pipeline/steps/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,17 @@ import type { IPage } from '../../types.js';
import { render } from '../template.js';

import { isRecord, mapConcurrent } from '../../utils.js';


import { ProxyAgent, fetch as undiciFetch } from 'undici';

/** Returns a fetch function that routes through the system proxy if configured. */
function getProxyFetch(): typeof fetch {
const proxyUrl = process.env.HTTPS_PROXY ?? process.env.https_proxy
?? process.env.HTTP_PROXY ?? process.env.http_proxy
?? process.env.ALL_PROXY ?? process.env.all_proxy;
if (!proxyUrl) return fetch;
const dispatcher = new ProxyAgent(proxyUrl);
return (input, init) => undiciFetch(input as Parameters<typeof undiciFetch>[0], { ...(init as object), dispatcher }) as unknown as Promise<Response>;
}

/** Single URL fetch helper */
async function fetchSingle(
Expand All @@ -29,7 +38,8 @@ async function fetchSingle(
}

if (page === null) {
const resp = await fetch(finalUrl, { method: method.toUpperCase(), headers: renderedHeaders });
const proxyFetch = getProxyFetch();
const resp = await proxyFetch(finalUrl, { method: method.toUpperCase(), headers: renderedHeaders });
if (!resp.ok) {
throw new CliError('FETCH_ERROR', `HTTP ${resp.status} ${resp.statusText} from ${finalUrl}`);
}
Expand Down