@sap-ux/backend-proxy-middleware 0.6.26 → 0.6.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/base/config.d.ts +2 -10
- package/dist/base/config.js +9 -32
- package/dist/base/proxy.js +5 -2
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -123,8 +123,7 @@ If you want to configure the proxy to send requests from a certain path `/servic
|
|
|
123
123
|
```
|
|
124
124
|
|
|
125
125
|
### [Providing Proxy Configuration](#providing-proxy-configuration)
|
|
126
|
-
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.
|
|
127
|
-
**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"`**.
|
|
126
|
+
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.
|
|
128
127
|
|
|
129
128
|
```
|
|
130
129
|
- name: backend-proxy-middleware
|
|
@@ -136,6 +135,7 @@ By default the `backend-proxy-middleware` will read the proxy configuration from
|
|
|
136
135
|
url: https://my.backend.example:1234
|
|
137
136
|
|
|
138
137
|
```
|
|
138
|
+
**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.
|
|
139
139
|
## Programmatic Usage
|
|
140
140
|
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.
|
|
141
141
|
|
package/dist/base/config.d.ts
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Updates the proxy configuration with values from runtime args (highest priority), given config value or environment variables.
|
|
3
3
|
*
|
|
4
4
|
* @param proxyFromConfig - optional proxy string from configuration
|
|
5
|
-
* @returns proxy server if required, otherwise undefined
|
|
6
5
|
*/
|
|
7
|
-
export declare function
|
|
8
|
-
/**
|
|
9
|
-
* Checks if a host is excluded from user's corporate proxy.
|
|
10
|
-
*
|
|
11
|
-
* @param url - url to be checked
|
|
12
|
-
* @returns true if host is excluded from user's corporate server, false otherwise
|
|
13
|
-
*/
|
|
14
|
-
export declare const isHostExcludedFromProxy: (url: string) => boolean;
|
|
6
|
+
export declare function updateProxyEnv(proxyFromConfig?: string): void;
|
|
15
7
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/base/config.js
CHANGED
|
@@ -1,46 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.updateProxyEnv = void 0;
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Updates the proxy configuration with values from runtime args (highest priority), given config value or environment variables.
|
|
6
6
|
*
|
|
7
7
|
* @param proxyFromConfig - optional proxy string from configuration
|
|
8
|
-
* @returns proxy server if required, otherwise undefined
|
|
9
8
|
*/
|
|
10
|
-
function
|
|
9
|
+
function updateProxyEnv(proxyFromConfig) {
|
|
11
10
|
let proxyFromArgs;
|
|
12
11
|
process.argv.forEach((arg) => {
|
|
13
12
|
if (arg.match(/proxy=/g)) {
|
|
14
13
|
proxyFromArgs = arg.split('=')[1];
|
|
15
14
|
}
|
|
16
15
|
});
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
process.env.
|
|
20
|
-
process.env.
|
|
21
|
-
process.env.HTTP_PROXY ||
|
|
22
|
-
process.env.https_proxy ||
|
|
23
|
-
process.env.HTTPS_PROXY ||
|
|
24
|
-
process.env.npm_config_proxy ||
|
|
25
|
-
process.env.npm_config_https_proxy);
|
|
26
|
-
}
|
|
27
|
-
exports.getCorporateProxyServer = getCorporateProxyServer;
|
|
28
|
-
/**
|
|
29
|
-
* Checks if a host is excluded from user's corporate proxy.
|
|
30
|
-
*
|
|
31
|
-
* @param url - url to be checked
|
|
32
|
-
* @returns true if host is excluded from user's corporate server, false otherwise
|
|
33
|
-
*/
|
|
34
|
-
const isHostExcludedFromProxy = (url) => {
|
|
35
|
-
const noProxyConfig = process.env.no_proxy || process.env.npm_config_noproxy;
|
|
36
|
-
if (noProxyConfig === '*') {
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
const host = new URL(url).host;
|
|
41
|
-
const noProxyList = noProxyConfig ? noProxyConfig.split(',') : [];
|
|
42
|
-
return !!noProxyList.find((entry) => entry.startsWith('.') ? host.endsWith(entry) : host.endsWith(`.${entry}`));
|
|
16
|
+
const proxyFromFioriToolsConfig = proxyFromArgs || proxyFromConfig || process.env.FIORI_TOOLS_PROXY;
|
|
17
|
+
if (proxyFromFioriToolsConfig) {
|
|
18
|
+
process.env.npm_config_proxy = proxyFromFioriToolsConfig;
|
|
19
|
+
process.env.npm_config_https_proxy = proxyFromFioriToolsConfig;
|
|
43
20
|
}
|
|
44
|
-
}
|
|
45
|
-
exports.
|
|
21
|
+
}
|
|
22
|
+
exports.updateProxyEnv = updateProxyEnv;
|
|
46
23
|
//# sourceMappingURL=config.js.map
|
package/dist/base/proxy.js
CHANGED
|
@@ -23,6 +23,7 @@ const i18n_json_1 = __importDefault(require("./i18n.json"));
|
|
|
23
23
|
const store_1 = require("@sap-ux/store");
|
|
24
24
|
const config_1 = require("./config");
|
|
25
25
|
const bsp_1 = require("../ext/bsp");
|
|
26
|
+
const proxy_from_env_1 = require("proxy-from-env");
|
|
26
27
|
/**
|
|
27
28
|
* Collection of custom event handler for the proxy.
|
|
28
29
|
*/
|
|
@@ -333,8 +334,10 @@ function generateProxyMiddlewareOptions(backend, options = {}, logger = new logg
|
|
|
333
334
|
if (!proxyOptions.target) {
|
|
334
335
|
throw new Error(`Unable to determine target from configuration:\n${JSON.stringify(backend, null, 2)}`);
|
|
335
336
|
}
|
|
336
|
-
|
|
337
|
-
|
|
337
|
+
// update proxy config with values coming from args or ui5.yaml
|
|
338
|
+
config_1.updateProxyEnv(backend.proxy);
|
|
339
|
+
backend.proxy = proxy_from_env_1.getProxyForUrl(proxyOptions.target);
|
|
340
|
+
if (backend.proxy) {
|
|
338
341
|
proxyOptions.agent = new https_proxy_agent_1.HttpsProxyAgent(backend.proxy);
|
|
339
342
|
}
|
|
340
343
|
logger.info(`Backend proxy created for ${proxyOptions.target} ${backend.path ? backend.path : ''}`);
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"bugs": {
|
|
10
10
|
"url": "https://github.com/SAP/open-ux-tools/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Abackend-proxy-middleware"
|
|
11
11
|
},
|
|
12
|
-
"version": "0.6.
|
|
12
|
+
"version": "0.6.28",
|
|
13
13
|
"license": "Apache-2.0",
|
|
14
14
|
"author": "@SAP/ux-tools-team",
|
|
15
15
|
"main": "dist/index.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"!dist/**/*.map"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@sap-ux/axios-extension": "0.10.
|
|
24
|
+
"@sap-ux/axios-extension": "0.10.3",
|
|
25
25
|
"@sap-ux/btp-utils": "0.11.2",
|
|
26
26
|
"@sap-ux/logger": "0.3.1",
|
|
27
27
|
"@sap-ux/store": "0.3.5",
|
|
@@ -30,12 +30,14 @@
|
|
|
30
30
|
"http-proxy-middleware": "2.0.1",
|
|
31
31
|
"https-proxy-agent": "5.0.0",
|
|
32
32
|
"i18next": "20.3.2",
|
|
33
|
-
"prompts": "2.4.2"
|
|
33
|
+
"prompts": "2.4.2",
|
|
34
|
+
"proxy-from-env": "1.1.0"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
37
|
"@types/express": "4.17.13",
|
|
37
38
|
"@types/http-proxy": "^1.17.5",
|
|
38
39
|
"@types/prompts": "2.0.14",
|
|
40
|
+
"@types/proxy-from-env": "1.0.1",
|
|
39
41
|
"@types/supertest": "2.0.12",
|
|
40
42
|
"express": "4.17.2",
|
|
41
43
|
"nock": "13.2.4",
|