@sap-ux/ui5-proxy-middleware 1.4.20 → 1.4.22

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.
@@ -1,7 +1,8 @@
1
1
  import type { ClientRequest, IncomingMessage, ServerResponse } from 'http';
2
2
  import type { ToolsLogger } from '@sap-ux/logger';
3
3
  import { type Manifest } from '@sap-ux/project-access';
4
- import type { NextFunction, Request, Response } from 'express';
4
+ import type { RequestHandler, NextFunction, Request, Response } from 'express';
5
+ import type http from 'http';
5
6
  import type { ProxyConfig } from './types';
6
7
  import type { Url } from 'url';
7
8
  import type { ReaderCollection } from '@ui5/fs';
@@ -67,11 +68,14 @@ export declare const getYamlFile: (args: string[]) => string;
67
68
  export declare const getWebAppFolderFromYaml: (ui5YamlPath: string) => Promise<string>;
68
69
  /**
69
70
  * Sends HTML content as a response.
71
+ * Ensure compliance with common APIs in express and connect.
70
72
  *
71
73
  * @param res - The http response object
72
74
  * @param html - The HTML content
73
75
  */
74
- export declare const setHtmlResponse: (res: any, html: string) => void;
76
+ export declare const sendResponse: (res: (Response | http.ServerResponse) & {
77
+ _livereload?: boolean;
78
+ }, html: string) => void;
75
79
  /**
76
80
  * Determines which UI5 version to use when previewing the application.
77
81
  *
@@ -124,4 +128,13 @@ export declare function proxyErrorHandler(err: Error & {
124
128
  next?: Function;
125
129
  originalUrl?: string;
126
130
  }, logger: ToolsLogger, _res?: ServerResponse, _target?: string | Partial<Url>): void;
131
+ /**
132
+ * Adjust UI5 bootstrap URLs to load directly from UI5 CDN.
133
+ *
134
+ * @param ui5Configs the UI5 configuration of the ui5-proxy-middleware
135
+ * @param rootProject the project root
136
+ * @param logger logger to be used when running the middleware
137
+ * @returns RequestHandler to adjust bootstraps
138
+ */
139
+ export declare function directLoadProxy(ui5Configs: ProxyConfig[], rootProject: ReaderCollection, logger: ToolsLogger): RequestHandler;
127
140
  //# sourceMappingURL=utils.d.ts.map
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.filterCompressedHtmlFiles = exports.injectScripts = exports.setHtmlResponse = exports.getWebAppFolderFromYaml = exports.getYamlFile = exports.getHtmlFile = exports.hideProxyCredentials = exports.getCorporateProxyServer = exports.proxyRequestHandler = exports.proxyResponseHandler = void 0;
3
+ exports.filterCompressedHtmlFiles = exports.injectScripts = exports.sendResponse = exports.getWebAppFolderFromYaml = exports.getYamlFile = exports.getHtmlFile = exports.hideProxyCredentials = exports.getCorporateProxyServer = exports.proxyRequestHandler = exports.proxyResponseHandler = void 0;
4
4
  exports.updateProxyEnv = updateProxyEnv;
5
5
  exports.resolveUI5Version = resolveUI5Version;
6
6
  exports.injectUI5Url = injectUI5Url;
7
7
  exports.proxyErrorHandler = proxyErrorHandler;
8
+ exports.directLoadProxy = directLoadProxy;
8
9
  const project_access_1 = require("@sap-ux/project-access");
9
10
  const ui5_config_1 = require("@sap-ux/ui5-config");
10
11
  const fs_1 = require("fs");
@@ -163,11 +164,12 @@ const getWebAppFolderFromYaml = async (ui5YamlPath) => {
163
164
  exports.getWebAppFolderFromYaml = getWebAppFolderFromYaml;
164
165
  /**
165
166
  * Sends HTML content as a response.
167
+ * Ensure compliance with common APIs in express and connect.
166
168
  *
167
169
  * @param res - The http response object
168
170
  * @param html - The HTML content
169
171
  */
170
- const setHtmlResponse = (res, html) => {
172
+ const sendResponse = (res, html) => {
171
173
  if (res['_livereload']) {
172
174
  res.write(html);
173
175
  res.end();
@@ -180,7 +182,7 @@ const setHtmlResponse = (res, html) => {
180
182
  res.end();
181
183
  }
182
184
  };
183
- exports.setHtmlResponse = setHtmlResponse;
185
+ exports.sendResponse = sendResponse;
184
186
  /**
185
187
  * Determines which UI5 version to use when previewing the application.
186
188
  *
@@ -259,7 +261,7 @@ const injectScripts = async (req, res, next, ui5Configs, rootProject) => {
259
261
  else {
260
262
  const originalHtml = await files[0].getString();
261
263
  const html = injectUI5Url(originalHtml, ui5Configs);
262
- (0, exports.setHtmlResponse)(res, html);
264
+ (0, exports.sendResponse)(res, html);
263
265
  }
264
266
  }
265
267
  catch (error) {
@@ -307,4 +309,23 @@ function proxyErrorHandler(err, req, logger, _res, _target) {
307
309
  logger.debug((0, i18n_1.t)('error.noCodeError', { error: JSON.stringify(err, null, 2), request: req.originalUrl }));
308
310
  }
309
311
  }
312
+ /**
313
+ * Adjust UI5 bootstrap URLs to load directly from UI5 CDN.
314
+ *
315
+ * @param ui5Configs the UI5 configuration of the ui5-proxy-middleware
316
+ * @param rootProject the project root
317
+ * @param logger logger to be used when running the middleware
318
+ * @returns RequestHandler to adjust bootstraps
319
+ */
320
+ function directLoadProxy(ui5Configs, rootProject, logger) {
321
+ return async (req, res, next) => {
322
+ try {
323
+ await (0, exports.injectScripts)(req, res, next, ui5Configs, rootProject);
324
+ }
325
+ catch (error) {
326
+ logger.error(error);
327
+ next(error);
328
+ }
329
+ };
330
+ }
310
331
  //# sourceMappingURL=utils.js.map
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { ui5Proxy } from './base';
1
+ export { ui5Proxy, directLoadProxy } from './base';
2
2
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ui5Proxy = void 0;
3
+ exports.directLoadProxy = exports.ui5Proxy = void 0;
4
4
  var base_1 = require("./base");
5
5
  Object.defineProperty(exports, "ui5Proxy", { enumerable: true, get: function () { return base_1.ui5Proxy; } });
6
+ Object.defineProperty(exports, "directLoadProxy", { enumerable: true, get: function () { return base_1.directLoadProxy; } });
6
7
  //# sourceMappingURL=index.js.map
@@ -94,16 +94,7 @@ module.exports = async ({ resources, options }) => {
94
94
  }
95
95
  }
96
96
  if (directLoad) {
97
- const directLoadProxy = (async (req, res, next) => {
98
- try {
99
- await (0, base_1.injectScripts)(req, res, next, ui5Configs, resources.rootProject);
100
- }
101
- catch (error) {
102
- logger.error(error);
103
- next(error);
104
- }
105
- });
106
- routes.push({ route: '*.html', handler: directLoadProxy });
97
+ routes.push({ route: '*.html', handler: (0, base_1.directLoadProxy)(ui5Configs, resources.rootProject, logger) });
107
98
  }
108
99
  return createRequestHandler(routes);
109
100
  };
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.4.20",
12
+ "version": "1.4.22",
13
13
  "license": "Apache-2.0",
14
14
  "author": "@SAP/ux-tools-team",
15
15
  "main": "dist/index.js",
@@ -26,8 +26,8 @@
26
26
  "https-proxy-agent": "5.0.1",
27
27
  "i18next": "20.6.1",
28
28
  "proxy-from-env": "1.1.0",
29
- "@sap-ux/logger": "0.6.0",
30
- "@sap-ux/ui5-config": "0.26.5"
29
+ "@sap-ux/ui5-config": "0.26.5",
30
+ "@sap-ux/logger": "0.6.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/express": "4.17.21",
@@ -37,7 +37,7 @@
37
37
  "nock": "13.4.0",
38
38
  "supertest": "6.3.3",
39
39
  "yaml": "2.2.2",
40
- "@sap-ux/project-access": "1.29.17"
40
+ "@sap-ux/project-access": "1.29.18"
41
41
  },
42
42
  "ui5": {
43
43
  "dependencies": []