@forge/cli

13.4.0-next.5-experimental-016ed9d13.4.0-next.5-experimental-c575574
out/command-line/proxy.js
+out/command-line/proxy.jsNew file
+53
Index: package/out/command-line/proxy.js
===================================================================
--- package/out/command-line/proxy.js
+++ package/out/command-line/proxy.js
@@ -0,0 +1,53 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.setupProxy = setupProxy;
+const tslib_1 = require("tslib");
+const cli_shared_1 = require("@forge/cli-shared");
+const http_proxy_agent_1 = require("http-proxy-agent");
+const https_proxy_agent_1 = require("https-proxy-agent");
+const http_1 = tslib_1.__importDefault(require("http"));
+const https_1 = tslib_1.__importDefault(require("https"));
+const undici_1 = require("undici");
+function parseProxyUrl(proxyUrl) {
+    try {
+        const parsedUrl = new URL(proxyUrl);
+        if (parsedUrl.protocol === 'http:' || parsedUrl.protocol === 'https:') {
+            return parsedUrl;
+        }
+    }
+    catch (e) {
+        return undefined;
+    }
+}
+function setupProxy() {
+    const cachedConf = cli_shared_1.CachedConf.getCache(cli_shared_1.CONFIG_PROJECT_NAME);
+    const proxyUrl = cachedConf.get('proxy');
+    if (proxyUrl && proxyUrl.trim()) {
+        const proxy = parseProxyUrl(proxyUrl);
+        if (!proxy) {
+            return undefined;
+        }
+        let httpAgent;
+        let httpsAgent;
+        let undiciProxyAgent;
+        if (process.env.NODE_TLS_REJECT_UNAUTHORIZED === '0') {
+            httpAgent = new http_proxy_agent_1.HttpProxyAgent(proxyUrl, { rejectUnauthorized: false });
+            httpsAgent = new https_proxy_agent_1.HttpsProxyAgent(proxyUrl, { rejectUnauthorized: false });
+            undiciProxyAgent = new undici_1.ProxyAgent({
+                uri: proxyUrl,
+                requestTls: { rejectUnauthorized: false },
+                proxyTls: { rejectUnauthorized: false }
+            });
+        }
+        else {
+            httpAgent = new http_proxy_agent_1.HttpProxyAgent(proxyUrl);
+            httpsAgent = new https_proxy_agent_1.HttpsProxyAgent(proxyUrl);
+            undiciProxyAgent = new undici_1.ProxyAgent(proxyUrl);
+        }
+        http_1.default.globalAgent = httpAgent;
+        https_1.default.globalAgent = httpsAgent;
+        (0, undici_1.setGlobalDispatcher)(undiciProxyAgent);
+        return { httpAgent, httpsAgent, undiciProxyAgent, proxy };
+    }
+}
+//# sourceMappingURL=proxy.js.map
\ No newline at end of file