@sap-ux/ui5-proxy-middleware 1.6.0 → 1.6.1

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
@@ -3,14 +3,17 @@
3
3
  The `@sap-ux/ui5-proxy-middleware` is a [Custom UI5 Server Middleware](https://sap.github.io/ui5-tooling/pages/extensibility/CustomServerMiddleware) for loading the UI5 sources in your application. It can be used either with the `ui5 serve` or the `fiori run` commands.
4
4
 
5
5
  ## Configuration Options
6
- | Option | Default Value | Description |
7
- | ------------ | ------------- | ----------- |
8
- | `ui5` | `object` | List of mount paths and target urls that should be handled by the proxy. If not provided then `/resources` and `/test-resources` are proxied to `https://ui5.sap.com` |
9
- | `version` | `undefined` | The UI5 version. If this property is not defined, then the `minUI5Version` from the `manifest.json` will be used |
10
- | `secure` | true | Defines if SSL certs should be verified |
11
- | `debug` | false | Enables debug output |
12
- | `proxy` | `undefined` | Use for adding corporate proxy configuration |
13
- | `directLoad` | false | Defines whether the UI5 sources should be loaded directly from UI5 CDN |
6
+ | Option | Value Type | Requirement Type | Default Value | Description |
7
+ | ------------ | ------------- |------------- | ----------- |----------- |
8
+ | `ui5` | object | optional | --- | Configuration object for the UI5 proxy middleware |
9
+ | `ui5.path` | string | optional | `/resources`, `/test-resources` | Path that is to be proxied |
10
+ | `ui5.url` | string | optional |`https://ui5.sap.com` | URL pointing to the resources |
11
+ | `ui5.pathReplace`| string | optional | `undefined` | If provided then the path will be replaced with this value before forwarding |
12
+ | `ui5.version` | string | optional |`undefined` | The UI5 version. If this property is not defined, then the `minUI5Version` from the `manifest.json` will be used |
13
+ | `secure` | boolean | optional | true | Defines if SSL certs should be verified |
14
+ | `debug` | boolean | optional | false | Enables debug output |
15
+ | `proxy` | string | optional | `undefined` | Use for adding corporate proxy configuration |
16
+ | `directLoad` | boolean | optional | false | Defines whether the UI5 sources should be loaded directly from UI5 CDN |
14
17
 
15
18
  ## Usage
16
19
  In order to use the middleware this is the minimal configuration that you need to provide in the `ui5.yaml` of your application. All requests to `/resources` and `/test-resources` will be proxied to the latest UI5 version at https://ui5.sap.com.
@@ -40,7 +43,7 @@ server:
40
43
  url: https://ui5.sap.com
41
44
  ```
42
45
 
43
- Alternatively you can use the following syntax if all paths should be proxied to the same url.
46
+ Alternatively you can use the following syntax if all paths should be proxied to the same URL.
44
47
 
45
48
  ```Yaml
46
49
  server:
@@ -54,10 +57,11 @@ server:
54
57
  - /test-resources
55
58
  url: https://ui5.sap.com
56
59
  ```
57
- **NOTE: You can't mix both syntaxes!**
60
+
61
+ **NOTE: You can't mix the syntaxes!**
58
62
 
59
63
  ### Loading a specific UI5 version
60
- To load a specific a UI5 version in your application you can use the `version` parameter, e.g.
64
+ To load a specific UI5 version in your application you can use the `version` parameter, e.g.
61
65
 
62
66
  ```Yaml
63
67
  server:
@@ -92,6 +96,23 @@ server:
92
96
  directLoad: true
93
97
  ```
94
98
 
99
+ ### Loading UI5 sources from a different Host
100
+ If you want to load UI5 sources from a different host, then you can set the property `pathReplace` to point to the desired resources. If provided then the `path` will be replaced with this value before forwarding.
101
+
102
+ **NOTE: using `pathReplace` will not consider a specified UI5 version. If a specific UI5 version is needed, then it needs to be part of the `pathReplace`.**
103
+
104
+ ```Yaml
105
+ server:
106
+ customMiddleware:
107
+ - name: ui5-proxy-middleware
108
+ afterMiddleware: compression
109
+ configuration:
110
+ ui5:
111
+ - path: /resources
112
+ url: https://my.backend.example:1234
113
+ pathReplace: /sap/public/ui5/resources
114
+ ```
115
+
95
116
  ### Adding corporate proxy configuration
96
117
  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.
97
118
 
@@ -39,9 +39,7 @@ const ui5Proxy = (config, options, filter, logger = new logger_1.ToolsLogger({
39
39
  },
40
40
  target: config.url,
41
41
  changeOrigin: true,
42
- pathRewrite: (path, _req) => {
43
- return path.startsWith(config.path) ? ui5Ver + path : ui5Ver + config.path + path;
44
- },
42
+ pathRewrite: (0, utils_1.getPathRewrite)(config, ui5Ver),
45
43
  pathFilter: proxyFilter,
46
44
  ...options
47
45
  };
@@ -1,9 +1,25 @@
1
1
  import type { NextFunction } from 'express';
2
2
  import type { IncomingMessage } from 'http';
3
3
  export interface ProxyConfig {
4
+ /**
5
+ * Path that is to be proxied.
6
+ */
4
7
  path: string;
8
+ /**
9
+ * If provided then the path will be replaced with this value before forwarding.
10
+ */
11
+ pathReplace?: string;
12
+ /**
13
+ * The target URL to proxy the request to.
14
+ */
5
15
  url: string;
16
+ /**
17
+ * If provided then the proxy will try to load the specified version of UI5 resources.
18
+ */
6
19
  version?: string;
20
+ /**
21
+ * If set then it will override the proxy settings from node.
22
+ */
7
23
  proxy?: string;
8
24
  }
9
25
  export interface UI5ProxyRequest {
@@ -1,4 +1,5 @@
1
1
  import type { ClientRequest, IncomingMessage, ServerResponse } from 'http';
2
+ import type { Options } from 'http-proxy-middleware';
2
3
  import type { ToolsLogger } from '@sap-ux/logger';
3
4
  import { type Manifest } from '@sap-ux/project-access';
4
5
  import type { RequestHandler, NextFunction, Request, Response } from 'express';
@@ -131,4 +132,12 @@ export declare function proxyErrorHandler(err: Error & {
131
132
  * @returns RequestHandler to adjust bootstraps
132
133
  */
133
134
  export declare function directLoadProxy(ui5Configs: ProxyConfig[], rootProject: ReaderCollection, logger: ToolsLogger): RequestHandler;
135
+ /**
136
+ * Create a rewrite based on the provided configuration.
137
+ *
138
+ * @param config proxy configuration
139
+ * @param ui5Ver UI5 version string
140
+ * @returns a path rewrite
141
+ */
142
+ export declare function getPathRewrite(config: ProxyConfig, ui5Ver: string): Options['pathRewrite'];
134
143
  //# sourceMappingURL=utils.d.ts.map
@@ -6,6 +6,7 @@ exports.resolveUI5Version = resolveUI5Version;
6
6
  exports.injectUI5Url = injectUI5Url;
7
7
  exports.proxyErrorHandler = proxyErrorHandler;
8
8
  exports.directLoadProxy = directLoadProxy;
9
+ exports.getPathRewrite = getPathRewrite;
9
10
  const project_access_1 = require("@sap-ux/project-access");
10
11
  const constants_1 = require("./constants");
11
12
  const i18n_1 = require("../i18n");
@@ -310,4 +311,19 @@ function directLoadProxy(ui5Configs, rootProject, logger) {
310
311
  }
311
312
  };
312
313
  }
314
+ /**
315
+ * Create a rewrite based on the provided configuration.
316
+ *
317
+ * @param config proxy configuration
318
+ * @param ui5Ver UI5 version string
319
+ * @returns a path rewrite
320
+ */
321
+ function getPathRewrite(config, ui5Ver) {
322
+ if (config.pathReplace) {
323
+ // Remove trailing slash from pathReplace if present
324
+ const sanitizedPathReplace = config.pathReplace?.replace(/\/$/, '');
325
+ return (path) => path.replace(config.path, sanitizedPathReplace);
326
+ }
327
+ return (path) => (path.startsWith(config.path) ? ui5Ver + path : ui5Ver + config.path + path);
328
+ }
313
329
  //# sourceMappingURL=utils.js.map
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.6.0",
12
+ "version": "1.6.1",
13
13
  "license": "Apache-2.0",
14
14
  "author": "@SAP/ux-tools-team",
15
15
  "main": "dist/index.js",