@sap-ux/ui5-proxy-middleware 1.1.13 → 1.1.15

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 CHANGED
@@ -92,7 +92,7 @@ server:
92
92
  ```
93
93
 
94
94
  ### Adding corporate proxy configuration
95
- If you are behind a corporate proxy then you can provide your corporate proxy configuration as follows.
95
+ By default the `ui5-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.
96
96
 
97
97
  ```Yaml
98
98
  server:
@@ -107,6 +107,7 @@ server:
107
107
  url: https://ui5.sap.com
108
108
  proxy: https://my.corporate.proxy.example
109
109
  ```
110
+ **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://ui5.sap.com` from the proxy you will need to set `noproxy` to `npm config set noproxy ".sap.com"`. Note the leading `.`, if you provide only `sap.com`, then it will not work.
110
111
 
111
112
  ## Programmatic Usage
112
113
  Alternatively you can only use the underlying proxy function, e.g. for the case when you want to incorporate the `ui5-proxy-middleware` functionality in your own middleware.
@@ -39,13 +39,12 @@ export declare const getCorporateProxyServer: (yamlProxyServer: string | undefin
39
39
  */
40
40
  export declare const hideProxyCredentials: (proxy: string | undefined) => string | undefined;
41
41
  /**
42
- * Checks if a host is excluded from user's corporate proxy.
42
+ * Checks if a host should be proxied through user's corporate proxy.
43
43
  *
44
44
  * @param url - url to be checked
45
- * @param noProxyConfig - user's no_proxy configuration
46
- * @returns true if host is excluded from user's corporate server, false otherwise
45
+ * @returns false if host is excluded from user's corporate server, true otherwise
47
46
  */
48
- export declare const isHostExcludedFromProxy: (url: string, noProxyConfig?: string | undefined) => boolean;
47
+ export declare const isProxyRequired: (url: string) => boolean;
49
48
  /**
50
49
  * Returns the name of html file, which is used to preview the application, from the URL.
51
50
  *
@@ -9,12 +9,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.proxyErrorHandler = exports.filterCompressedHtmlFiles = exports.injectScripts = exports.injectUI5Url = exports.resolveUI5Version = exports.getUI5VersionFromManifest = exports.getManifest = exports.setHtmlResponse = exports.getWebAppFolderFromYaml = exports.getYamlFile = exports.getHtmlFile = exports.isHostExcludedFromProxy = exports.hideProxyCredentials = exports.getCorporateProxyServer = exports.proxyRequestHandler = exports.proxyResponseHandler = void 0;
12
+ exports.proxyErrorHandler = exports.filterCompressedHtmlFiles = exports.injectScripts = exports.injectUI5Url = exports.resolveUI5Version = exports.getUI5VersionFromManifest = exports.getManifest = exports.setHtmlResponse = exports.getWebAppFolderFromYaml = exports.getYamlFile = exports.getHtmlFile = exports.isProxyRequired = exports.hideProxyCredentials = exports.getCorporateProxyServer = exports.proxyRequestHandler = exports.proxyResponseHandler = void 0;
13
13
  const ui5_config_1 = require("@sap-ux/ui5-config");
14
14
  const fs_1 = require("fs");
15
15
  const path_1 = require("path");
16
16
  const constants_1 = require("./constants");
17
17
  const i18n_1 = require("../i18n");
18
+ const proxy_from_env_1 = require("proxy-from-env");
18
19
  /**
19
20
  * Handler for the proxy response event.
20
21
  * Sets an Etag which will be used for re-validation of the cached UI5 sources.
@@ -52,14 +53,27 @@ exports.proxyRequestHandler = proxyRequestHandler;
52
53
  * @returns User's proxy configuration or undefined
53
54
  */
54
55
  const getCorporateProxyServer = (yamlProxyServer) => {
55
- return (yamlProxyServer ||
56
- process.env.FIORI_TOOLS_PROXY ||
57
- process.env.http_proxy ||
56
+ let proxyFromArgs;
57
+ process.argv.forEach((arg) => {
58
+ if (arg.match(/proxy=/g)) {
59
+ proxyFromArgs = arg.split('=')[1];
60
+ }
61
+ });
62
+ const proxyFromFioriToolsConfig = proxyFromArgs || yamlProxyServer || process.env.FIORI_TOOLS_PROXY;
63
+ const proxyFromOSEnvConfig = process.env.http_proxy ||
58
64
  process.env.HTTP_PROXY ||
59
65
  process.env.https_proxy ||
60
66
  process.env.HTTPS_PROXY ||
61
67
  process.env.npm_config_proxy ||
62
- process.env.npm_config_https_proxy);
68
+ process.env.npm_config_https_proxy;
69
+ if (proxyFromFioriToolsConfig) {
70
+ process.env.npm_config_proxy = proxyFromFioriToolsConfig;
71
+ process.env.npm_config_https_proxy = proxyFromFioriToolsConfig;
72
+ return proxyFromFioriToolsConfig;
73
+ }
74
+ else {
75
+ return proxyFromOSEnvConfig;
76
+ }
63
77
  };
64
78
  exports.getCorporateProxyServer = getCorporateProxyServer;
65
79
  /**
@@ -80,23 +94,15 @@ const hideProxyCredentials = (proxy) => {
80
94
  };
81
95
  exports.hideProxyCredentials = hideProxyCredentials;
82
96
  /**
83
- * Checks if a host is excluded from user's corporate proxy.
97
+ * Checks if a host should be proxied through user's corporate proxy.
84
98
  *
85
99
  * @param url - url to be checked
86
- * @param noProxyConfig - user's no_proxy configuration
87
- * @returns true if host is excluded from user's corporate server, false otherwise
100
+ * @returns false if host is excluded from user's corporate server, true otherwise
88
101
  */
89
- const isHostExcludedFromProxy = (url, noProxyConfig = process.env.no_proxy || process.env.npm_config_noproxy) => {
90
- if (noProxyConfig === '*') {
91
- return true;
92
- }
93
- else {
94
- const host = new URL(url).host;
95
- const noProxyList = noProxyConfig ? noProxyConfig.split(',') : [];
96
- return !!noProxyList.find((entry) => entry.startsWith('.') ? host.endsWith(entry) : host.endsWith(`.${entry}`));
97
- }
102
+ const isProxyRequired = (url) => {
103
+ return proxy_from_env_1.getProxyForUrl(url) ? true : false;
98
104
  };
99
- exports.isHostExcludedFromProxy = isHostExcludedFromProxy;
105
+ exports.isProxyRequired = isProxyRequired;
100
106
  /**
101
107
  * Returns the name of html file, which is used to preview the application, from the URL.
102
108
  *
@@ -72,7 +72,7 @@ module.exports = ({ options }) => __awaiter(void 0, void 0, void 0, function* ()
72
72
  url: envUI5Url || ui5.url,
73
73
  version: ui5Version
74
74
  };
75
- if (corporateProxyServer && !base_1.isHostExcludedFromProxy(ui5Config.url)) {
75
+ if (corporateProxyServer && base_1.isProxyRequired(ui5Config.url)) {
76
76
  proxyOptions.agent = new https_proxy_agent_1.HttpsProxyAgent(corporateProxyServer);
77
77
  }
78
78
  routes.push({ route: ui5Config.path, handler: base_1.ui5Proxy(ui5Config, proxyOptions) });
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%3Aui5-proxy-middleware"
11
11
  },
12
- "version": "1.1.13",
12
+ "version": "1.1.15",
13
13
  "license": "Apache-2.0",
14
14
  "author": "@SAP/ux-tools-team",
15
15
  "main": "dist/index.js",
@@ -22,18 +22,21 @@
22
22
  ],
23
23
  "dependencies": {
24
24
  "@sap-ux/logger": "0.3.1",
25
- "@sap-ux/ui5-config": "0.15.3",
25
+ "@sap-ux/ui5-config": "0.15.4",
26
26
  "dotenv": "16.0.0",
27
27
  "http-proxy-middleware": "2.0.1",
28
28
  "https-proxy-agent": "5.0.0",
29
- "i18next": "20.3.2"
29
+ "i18next": "20.3.2",
30
+ "proxy-from-env": "1.1.0"
30
31
  },
31
32
  "devDependencies": {
32
- "@sap-ux/project-access": "1.0.0",
33
+ "@sap-ux/project-access": "1.0.1",
33
34
  "@types/express": "4.17.13",
35
+ "@types/supertest": "2.0.12",
36
+ "@types/proxy-from-env": "1.0.1",
34
37
  "express": "4.17.2",
35
38
  "nock": "13.2.4",
36
- "@types/supertest": "2.0.12",
39
+ "supertest": "6.2.2",
37
40
  "yaml": "2.0.0-10"
38
41
  },
39
42
  "ui5": {