diff --git a/installers/npm/binary.js b/installers/npm/binary.js index 6beacc5323..b2edf2c211 100644 --- a/installers/npm/binary.js +++ b/installers/npm/binary.js @@ -4,7 +4,6 @@ const cTable = require("console.table"); const libc = require("detect-libc"); const { join } = require("path"); const { spawnSync } = require("child_process"); -const { configureProxy } = require("./proxy"); const error = (msg) => { console.error(msg); @@ -112,11 +111,7 @@ const run = () => { const install = () => { const binary = getBinary(); - - const proxy = configureProxy(binary.url); - - binary.install(proxy); - + binary.install(); let pluginInstallCommand = `${binary.binaryPath} install --plugin`; let commands = [ `${pluginInstallCommand} supergraph@latest-0`, diff --git a/installers/npm/proxy.js b/installers/npm/proxy.js deleted file mode 100644 index 00e833c4c0..0000000000 --- a/installers/npm/proxy.js +++ /dev/null @@ -1,99 +0,0 @@ -/** - * - * NoProxy logic derived from Request project: - * https://github.com/request/request/blob/3c0cddc7c8eb60b470e9519da85896ed7ee0081e/lib/getProxyFromURI.js - * - */ - -const formatHostName = (hostname) => - hostname.replace(/^\.*/, ".").toLowerCase(); - -const parseNoProxyZone = (zone) => { - zone = zone.trim(); - - const zoneParts = zone.split(":", 2); - const zoneHost = formatHostName(zoneParts[0]); - const zonePort = zoneParts[1]; - const hasPort = zone.indexOf(":") > -1; - - return { hostname: zoneHost, port: zonePort, hasPort: hasPort }; -}; - -const urlInNoProxy = (requestURL, noProxy) => { - const port = - requestURL.port || (requestURL.protocol === "https:" ? "443" : "80"); - - // clean hostname - const hostname = formatHostName(requestURL.hostname); - - // convert to array - const noProxyList = noProxy.split(","); - - // iterate over noProxyList and find match with RequestURL - return noProxyList.map(parseNoProxyZone).some((noProxyZone) => { - const isMatchedAt = hostname.indexOf(noProxyZone.hostname); - const hostnameMatched = - isMatchedAt > -1 && - isMatchedAt === hostname.length - noProxyZone.hostname.length; - - if (noProxyZone.hasPort) { - return port === noProxyZone.port && hostnameMatched; - } - - return hostnameMatched; - }); -}; - -const getProxyEnv = (requestURL) => { - const noProxy = process.env.NO_PROXY || process.env.no_proxy || ""; - - // if the noProxy is a wildcard then return null - if (noProxy === "*") { - return null; - } - - // if the noProxy is not empty and the uri is found, return null - if (noProxy !== "" && urlInNoProxy(requestURL, noProxy)) { - return null; - } - - // get proxy based on request url's protocol - if (requestURL.protocol == "http:") { - return process.env.HTTP_PROXY || process.env.http_proxy || null; - } - - if (requestURL.protocol == "https:") { - return process.env.HTTPS_PROXY || process.env.https_proxy || null; - } - - // not a supported protocol... - return null; -}; - -const configureProxy = (requestURL) => { - const url = new URL(requestURL); - const env = getProxyEnv(url); - - // short circuit if null - if (!env) return null; - - // parse proxy url - const { hostname, port, protocol, username, password } = new URL(env); - - // return proxy object for axios request - return { - proxy: { - protocol, - hostname, - port, - auth: { - username, - password, - }, - }, - }; -}; - -module.exports = { - configureProxy, -};