@sap-ux/backend-proxy-middleware
Advanced tools
Comparing version 0.6.26 to 0.6.27
/** | ||
* Get the effective proxy string from runtime args (highest priority), given config value or environment variables. | ||
* Updates the proxy configuration with values from runtime args (highest priority), given config value or environment variables. | ||
* | ||
* @param proxyFromConfig - optional proxy string from configuration | ||
* @returns proxy server if required, otherwise undefined | ||
*/ | ||
export declare function getCorporateProxyServer(proxyFromConfig?: string): string | undefined; | ||
/** | ||
* Checks if a host is excluded from user's corporate proxy. | ||
* | ||
* @param url - url to be checked | ||
* @returns true if host is excluded from user's corporate server, false otherwise | ||
*/ | ||
export declare const isHostExcludedFromProxy: (url: string) => boolean; | ||
export declare function updateProxyEnv(proxyFromConfig?: string): void; | ||
//# sourceMappingURL=config.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isHostExcludedFromProxy = exports.getCorporateProxyServer = void 0; | ||
exports.updateProxyEnv = void 0; | ||
/** | ||
* Get the effective proxy string from runtime args (highest priority), given config value or environment variables. | ||
* Updates the proxy configuration with values from runtime args (highest priority), given config value or environment variables. | ||
* | ||
* @param proxyFromConfig - optional proxy string from configuration | ||
* @returns proxy server if required, otherwise undefined | ||
*/ | ||
function getCorporateProxyServer(proxyFromConfig) { | ||
function updateProxyEnv(proxyFromConfig) { | ||
let proxyFromArgs; | ||
@@ -17,31 +16,9 @@ process.argv.forEach((arg) => { | ||
}); | ||
return (proxyFromArgs || | ||
proxyFromConfig || | ||
process.env.FIORI_TOOLS_PROXY || | ||
process.env.http_proxy || | ||
process.env.HTTP_PROXY || | ||
process.env.https_proxy || | ||
process.env.HTTPS_PROXY || | ||
process.env.npm_config_proxy || | ||
process.env.npm_config_https_proxy); | ||
const proxyFromFioriToolsConfig = proxyFromArgs || proxyFromConfig || process.env.FIORI_TOOLS_PROXY; | ||
if (proxyFromFioriToolsConfig) { | ||
process.env.npm_config_proxy = proxyFromFioriToolsConfig; | ||
process.env.npm_config_https_proxy = proxyFromFioriToolsConfig; | ||
} | ||
} | ||
exports.getCorporateProxyServer = getCorporateProxyServer; | ||
/** | ||
* Checks if a host is excluded from user's corporate proxy. | ||
* | ||
* @param url - url to be checked | ||
* @returns true if host is excluded from user's corporate server, false otherwise | ||
*/ | ||
const isHostExcludedFromProxy = (url) => { | ||
const noProxyConfig = process.env.no_proxy || process.env.npm_config_noproxy; | ||
if (noProxyConfig === '*') { | ||
return true; | ||
} | ||
else { | ||
const host = new URL(url).host; | ||
const noProxyList = noProxyConfig ? noProxyConfig.split(',') : []; | ||
return !!noProxyList.find((entry) => entry.startsWith('.') ? host.endsWith(entry) : host.endsWith(`.${entry}`)); | ||
} | ||
}; | ||
exports.isHostExcludedFromProxy = isHostExcludedFromProxy; | ||
exports.updateProxyEnv = updateProxyEnv; | ||
//# sourceMappingURL=config.js.map |
@@ -26,2 +26,3 @@ "use strict"; | ||
const bsp_1 = require("../ext/bsp"); | ||
const proxy_from_env_1 = require("proxy-from-env"); | ||
/** | ||
@@ -337,4 +338,6 @@ * Collection of custom event handler for the proxy. | ||
} | ||
backend.proxy = config_1.getCorporateProxyServer(backend.proxy); | ||
if (backend.proxy && !config_1.isHostExcludedFromProxy(proxyOptions.target)) { | ||
// update proxy config with values coming from args or ui5.yaml | ||
config_1.updateProxyEnv(backend.proxy); | ||
backend.proxy = proxy_from_env_1.getProxyForUrl(proxyOptions.target); | ||
if (backend.proxy) { | ||
proxyOptions.agent = new https_proxy_agent_1.HttpsProxyAgent(backend.proxy); | ||
@@ -341,0 +344,0 @@ } |
@@ -12,3 +12,3 @@ { | ||
}, | ||
"version": "0.6.26", | ||
"version": "0.6.27", | ||
"license": "Apache-2.0", | ||
@@ -34,3 +34,4 @@ "author": "@SAP/ux-tools-team", | ||
"i18next": "20.3.2", | ||
"prompts": "2.4.2" | ||
"prompts": "2.4.2", | ||
"proxy-from-env": "1.1.0" | ||
}, | ||
@@ -41,2 +42,3 @@ "devDependencies": { | ||
"@types/prompts": "2.0.14", | ||
"@types/proxy-from-env": "1.0.1", | ||
"@types/supertest": "2.0.12", | ||
@@ -43,0 +45,0 @@ "express": "4.17.2", |
@@ -126,4 +126,3 @@ # `@sap-ux/backend-proxy-middleware` | ||
### [Providing Proxy Configuration](#providing-proxy-configuration) | ||
By default the `backend-proxy-middleware` will read the proxy configuration from the Node.js environment variables `proxy`, `https-proxy` and `noproxy`. If those variables are not set, then you can also provide the proxy configuration in the `ui5.yaml` file. | ||
**Please note: if you want to exclude any domains from the proxy then you will need to set the `noproxy` variable, e.g. `npm config set noproxy "sap.com"`**. | ||
By default the `backend-proxy-middleware` will read the proxy configuration from the OS environment variables `HTTP_PROXY`, `HTTPS_PROXY` and `NO_PROXY` or from the Node.js environment variables `proxy`, `https-proxy` and `noproxy`. If those variables are not set, then you can also provide the proxy configuration in the `ui5.yaml` file. | ||
@@ -140,2 +139,3 @@ ``` | ||
``` | ||
**Please note:** if you want to exclude any domains from the proxy then you will need to set the `noproxy` variable. E.g. if you want to exclude the `https://my.backend.example:1234` from the proxy you will need to set `noproxy` to `npm config set noproxy ".backend.example"`. Note the leading `.`, if you provide only `backend.example`, then it will not work. | ||
## Programmatic Usage | ||
@@ -142,0 +142,0 @@ Alternatively you can only use the underlying proxy function, e.g. for the case when you want to use the `backend-proxy-middleware` functionality in your `express` server. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
55908
11
9
811
+ Addedproxy-from-env@1.1.0
+ Addedproxy-from-env@1.1.0(transitive)