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

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,12 +1,15 @@
1
1
  import type { Filter, Options } from 'http-proxy-middleware';
2
+ import type { IncomingMessage, ServerResponse } from 'http';
2
3
  import type { ProxyConfig } from './types';
4
+ import { ToolsLogger } from '@sap-ux/logger';
3
5
  /**
4
6
  * Function for proxying UI5 sources.
5
7
  *
6
8
  * @param config - proxy configuration
7
9
  * @param options - additional configuration options
8
10
  * @param filter - custom filter function which will be applied to all requests
11
+ * @param logger - optional logger instance
9
12
  * @returns Proxy function to use
10
13
  */
11
- export declare const ui5Proxy: (config: ProxyConfig, options?: Options, filter?: Filter) => import("http-proxy-middleware").RequestHandler;
14
+ export declare const ui5Proxy: (config: ProxyConfig, options?: Options, filter?: Filter, logger?: ToolsLogger) => import("http-proxy-middleware").RequestHandler<IncomingMessage, ServerResponse<IncomingMessage>, (err?: any) => void>;
12
15
  //# sourceMappingURL=proxy.d.ts.map
@@ -12,28 +12,38 @@ const https_proxy_agent_1 = require("https-proxy-agent");
12
12
  * @param config - proxy configuration
13
13
  * @param options - additional configuration options
14
14
  * @param filter - custom filter function which will be applied to all requests
15
+ * @param logger - optional logger instance
15
16
  * @returns Proxy function to use
16
17
  */
17
- const ui5Proxy = (config, options, filter) => {
18
- const logger = new logger_1.ToolsLogger({
19
- transports: [new logger_1.UI5ToolingTransport({ moduleName: 'ui5-proxy-middleware' })]
20
- });
18
+ const ui5Proxy = (config, options, filter, logger = new logger_1.ToolsLogger({
19
+ transports: [new logger_1.UI5ToolingTransport({ moduleName: 'ui5-proxy-middleware' })]
20
+ })) => {
21
21
  const today = new Date();
22
22
  const etag = `W/"${config.version || 'ui5-latest-' + today.getDate() + today.getMonth() + today.getFullYear()}"`;
23
23
  const ui5Ver = config.version ? `/${config.version}` : '';
24
+ let proxyFilter = utils_1.filterCompressedHtmlFiles;
25
+ if (filter) {
26
+ proxyFilter = filter;
27
+ }
24
28
  const proxyConfig = {
29
+ on: {
30
+ proxyReq: (proxyReq, _req, res) => {
31
+ (0, utils_1.proxyRequestHandler)(proxyReq, res, etag);
32
+ },
33
+ proxyRes: (proxyRes) => {
34
+ (0, utils_1.proxyResponseHandler)(proxyRes, etag);
35
+ },
36
+ error: (err, req, res, target) => {
37
+ (0, utils_1.proxyErrorHandler)(err, req, logger, res, target);
38
+ }
39
+ },
25
40
  target: config.url,
26
41
  changeOrigin: true,
27
- onProxyReq: (proxyReq, _req, res) => {
28
- (0, utils_1.proxyRequestHandler)(proxyReq, res, etag, logger);
42
+ pathRewrite: (path, _req) => {
43
+ return path.startsWith(config.path) ? ui5Ver + path : ui5Ver + config.path + path;
29
44
  },
30
- pathRewrite: { [config.path]: ui5Ver + config.path },
31
- onProxyRes: (proxyRes) => {
32
- (0, utils_1.proxyResponseHandler)(proxyRes, etag);
33
- },
34
- onError: (err, req, res, target) => {
35
- (0, utils_1.proxyErrorHandler)(err, req, logger, res, target);
36
- }
45
+ pathFilter: proxyFilter,
46
+ ...options
37
47
  };
38
48
  // update proxy config with values coming from args or ui5.yaml
39
49
  (0, utils_1.updateProxyEnv)(config.proxy);
@@ -41,12 +51,7 @@ const ui5Proxy = (config, options, filter) => {
41
51
  if (corporateProxy) {
42
52
  proxyConfig.agent = new https_proxy_agent_1.HttpsProxyAgent(corporateProxy);
43
53
  }
44
- Object.assign(proxyConfig, options);
45
- let proxyFilter = utils_1.filterCompressedHtmlFiles;
46
- if (filter) {
47
- proxyFilter = filter;
48
- }
49
- return (0, http_proxy_middleware_1.createProxyMiddleware)(proxyFilter, proxyConfig);
54
+ return (0, http_proxy_middleware_1.createProxyMiddleware)(proxyConfig);
50
55
  };
51
56
  exports.ui5Proxy = ui5Proxy;
52
57
  //# sourceMappingURL=proxy.js.map
@@ -6,6 +6,7 @@ import type http from 'http';
6
6
  import type { ProxyConfig } from './types';
7
7
  import type { Url } from 'url';
8
8
  import type { ReaderCollection } from '@ui5/fs';
9
+ import type { Socket } from 'node:net';
9
10
  /**
10
11
  * Handler for the proxy response event.
11
12
  * Sets an Etag which will be used for re-validation of the cached UI5 sources.
@@ -22,9 +23,8 @@ export declare const proxyResponseHandler: (proxyRes: IncomingMessage, etag: str
22
23
  * @param proxyReq - proxy request object
23
24
  * @param res - server response object
24
25
  * @param etag - Etag of the cached UI5 sources, normally the UI5 version
25
- * @param logger - Logger for loging the requests
26
26
  */
27
- export declare const proxyRequestHandler: (proxyReq: ClientRequest, res: ServerResponse, etag: string, logger: ToolsLogger) => void;
27
+ export declare const proxyRequestHandler: (proxyReq: ClientRequest, res: ServerResponse, etag: string) => void;
28
28
  /**
29
29
  * Get user's proxy configuration.
30
30
  *
@@ -94,8 +94,9 @@ export declare function injectUI5Url(originalHtml: string, ui5Configs: ProxyConf
94
94
  * @param next - the next function, used to forward the request to the next available handler
95
95
  * @param ui5Configs - the UI5 configuration of the ui5-proxy-middleware
96
96
  * @param rootProject - the root project
97
+ * @param logger - logger to be used
97
98
  */
98
- export declare const injectScripts: (req: Request, res: Response, next: NextFunction, ui5Configs: ProxyConfig[], rootProject: ReaderCollection) => Promise<void>;
99
+ export declare const injectScripts: (req: Request, res: Response, next: NextFunction, ui5Configs: ProxyConfig[], rootProject: ReaderCollection, logger?: ToolsLogger) => Promise<void>;
99
100
  /**
100
101
  * Filters comressed html files from UI5 CDN.
101
102
  * Avoid ERR_CONTENT_DECODING_FAILED on http request for gzip'd html files.
@@ -120,7 +121,7 @@ export declare function proxyErrorHandler(err: Error & {
120
121
  }, req: IncomingMessage & {
121
122
  next?: Function;
122
123
  originalUrl?: string;
123
- }, logger: ToolsLogger, _res?: ServerResponse, _target?: string | Partial<Url>): void;
124
+ }, logger: ToolsLogger, _res?: ServerResponse | Socket, _target?: string | Partial<Url>): void;
124
125
  /**
125
126
  * Adjust UI5 bootstrap URLs to load directly from UI5 CDN.
126
127
  *
@@ -29,10 +29,8 @@ exports.proxyResponseHandler = proxyResponseHandler;
29
29
  * @param proxyReq - proxy request object
30
30
  * @param res - server response object
31
31
  * @param etag - Etag of the cached UI5 sources, normally the UI5 version
32
- * @param logger - Logger for loging the requests
33
32
  */
34
- const proxyRequestHandler = (proxyReq, res, etag, logger) => {
35
- logger.debug(proxyReq.path);
33
+ const proxyRequestHandler = (proxyReq, res, etag) => {
36
34
  if (proxyReq.getHeader('if-none-match') === etag) {
37
35
  res.statusCode = 304;
38
36
  res.end();
@@ -232,12 +230,14 @@ function injectUI5Url(originalHtml, ui5Configs) {
232
230
  * @param next - the next function, used to forward the request to the next available handler
233
231
  * @param ui5Configs - the UI5 configuration of the ui5-proxy-middleware
234
232
  * @param rootProject - the root project
233
+ * @param logger - logger to be used
235
234
  */
236
- const injectScripts = async (req, res, next, ui5Configs, rootProject) => {
235
+ const injectScripts = async (req, res, next, ui5Configs, rootProject, logger) => {
237
236
  try {
238
237
  const htmlFileName = (0, exports.getHtmlFile)(req.url);
239
238
  const files = await rootProject.byGlob(`**/${htmlFileName}`);
240
239
  if (files.length === 0) {
240
+ logger?.warn('No HTML file found for direct load injection.');
241
241
  next();
242
242
  }
243
243
  else {
@@ -302,7 +302,7 @@ function proxyErrorHandler(err, req, logger, _res, _target) {
302
302
  function directLoadProxy(ui5Configs, rootProject, logger) {
303
303
  return async (req, res, next) => {
304
304
  try {
305
- await (0, exports.injectScripts)(req, res, next, ui5Configs, rootProject);
305
+ await (0, exports.injectScripts)(req, res, next, ui5Configs, rootProject, logger);
306
306
  }
307
307
  catch (error) {
308
308
  logger.error(error);
@@ -17,8 +17,7 @@ const dotenv_1 = __importDefault(require("dotenv"));
17
17
  function createProxyOptions(logger, config) {
18
18
  return {
19
19
  secure: config.secure !== undefined ? !!config.secure : true,
20
- logLevel: config.debug ? 'debug' : 'info',
21
- logProvider: () => logger
20
+ logger: config.debug ? logger : undefined
22
21
  };
23
22
  }
24
23
  /**
@@ -51,6 +50,7 @@ async function loadManifest(rootProject) {
51
50
  }
52
51
  module.exports = async ({ resources, options }) => {
53
52
  const logger = new logger_1.ToolsLogger({
53
+ logLevel: options.configuration?.debug ? logger_1.LogLevel.Debug : logger_1.LogLevel.Info,
54
54
  transports: [new logger_1.UI5ToolingTransport({ moduleName: 'ui5-proxy-middleware' })]
55
55
  });
56
56
  dotenv_1.default.config();
@@ -76,7 +76,7 @@ module.exports = async ({ resources, options }) => {
76
76
  // hide user and pass from proxy configuration for displaying it in the terminal
77
77
  const proxyInfo = (0, base_1.hideProxyCredentials)(corporateProxyServer);
78
78
  const proxyOptions = createProxyOptions(logger, config);
79
- logger.info(`Starting ui5-proxy-middleware using following configuration:\nproxy: '${proxyInfo}'\nsecure: '${proxyOptions.secure}'\nlog: '${proxyOptions.logLevel}''\ndirectLoad: '${directLoad}'`);
79
+ logger.info(`Starting ui5-proxy-middleware using following configuration:\nproxy: '${proxyInfo}'\nsecure: '${proxyOptions.secure}'\nlog: '${config.debug ? 'debug' : 'info'}' \ndirectLoad: '${directLoad}'`);
80
80
  const configs = Array.isArray(config.ui5) ? config.ui5 : [config.ui5];
81
81
  const ui5Configs = [];
82
82
  const routes = [];
@@ -89,7 +89,7 @@ module.exports = async ({ resources, options }) => {
89
89
  version: ui5Version,
90
90
  proxy: config.proxy
91
91
  };
92
- routes.push({ route: ui5Config.path, handler: (0, base_1.ui5Proxy)(ui5Config, proxyOptions) });
92
+ routes.push({ route: ui5Config.path, handler: (0, base_1.ui5Proxy)(ui5Config, proxyOptions, undefined, logger) });
93
93
  ui5Configs.push(ui5Config);
94
94
  }
95
95
  }
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.5.12",
12
+ "version": "1.6.0",
13
13
  "license": "Apache-2.0",
14
14
  "author": "@SAP/ux-tools-team",
15
15
  "main": "dist/index.js",
@@ -22,7 +22,7 @@
22
22
  ],
23
23
  "dependencies": {
24
24
  "dotenv": "16.3.1",
25
- "http-proxy-middleware": "2.0.9",
25
+ "http-proxy-middleware": "3.0.5",
26
26
  "https-proxy-agent": "5.0.1",
27
27
  "i18next": "25.3.0",
28
28
  "proxy-from-env": "1.1.0",