mirror of
https://github.com/astral-sh/setup-uv.git
synced 2026-01-09 21:32:14 +00:00
22 lines
546 B
TypeScript
22 lines
546 B
TypeScript
import { ProxyAgent, type RequestInit, fetch as undiciFetch } from "undici";
|
|
|
|
export function getProxyAgent() {
|
|
const httpProxy = process.env.HTTP_PROXY || process.env.http_proxy;
|
|
if (httpProxy) {
|
|
return new ProxyAgent(httpProxy);
|
|
}
|
|
|
|
const httpsProxy = process.env.HTTPS_PROXY || process.env.https_proxy;
|
|
if (httpsProxy) {
|
|
return new ProxyAgent(httpsProxy);
|
|
}
|
|
|
|
return undefined;
|
|
}
|
|
|
|
export const fetch = async (url: string, opts: RequestInit) =>
|
|
await undiciFetch(url, {
|
|
dispatcher: getProxyAgent(),
|
|
...opts,
|
|
});
|