http-proxy-middleware 3.0.1 → 3.0.3

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.
@@ -4,8 +4,8 @@ exports.getPlugins = getPlugins;
4
4
  const default_1 = require("./plugins/default");
5
5
  function getPlugins(options) {
6
6
  // don't load default errorResponsePlugin if user has specified their own
7
- const maybeErrorResponsePlugin = !!options.on?.error ? [] : [default_1.errorResponsePlugin];
8
- const defaultPlugins = !!options.ejectPlugins
7
+ const maybeErrorResponsePlugin = options.on?.error ? [] : [default_1.errorResponsePlugin];
8
+ const defaultPlugins = options.ejectPlugins
9
9
  ? [] // no default plugins when ejecting
10
10
  : [default_1.debugProxyErrorsPlugin, default_1.proxyEventsPlugin, default_1.loggerPlugin, ...maybeErrorResponsePlugin];
11
11
  const userPlugins = options.plugins ?? [];
@@ -5,6 +5,7 @@ export declare class HttpProxyMiddleware<TReq, TRes> {
5
5
  private proxyOptions;
6
6
  private proxy;
7
7
  private pathRewriter;
8
+ private logger;
8
9
  constructor(options: Options<TReq, TRes>);
9
10
  middleware: RequestHandler;
10
11
  private registerPlugins;
@@ -9,6 +9,7 @@ const PathRewriter = require("./path-rewriter");
9
9
  const Router = require("./router");
10
10
  const debug_1 = require("./debug");
11
11
  const function_1 = require("./utils/function");
12
+ const logger_1 = require("./logger");
12
13
  class HttpProxyMiddleware {
13
14
  constructor(options) {
14
15
  this.wsInternalSubscribed = false;
@@ -22,11 +23,11 @@ class HttpProxyMiddleware {
22
23
  this.proxy.web(req, res, activeProxyOptions);
23
24
  }
24
25
  catch (err) {
25
- next && next(err);
26
+ next?.(err);
26
27
  }
27
28
  }
28
29
  else {
29
- next && next();
30
+ next?.();
30
31
  }
31
32
  /**
32
33
  * Get the server object to subscribe to server events;
@@ -69,7 +70,14 @@ class HttpProxyMiddleware {
69
70
  * Determine whether request should be proxied.
70
71
  */
71
72
  this.shouldProxy = (pathFilter, req) => {
72
- return (0, path_filter_1.matchPathFilter)(pathFilter, req.url, req);
73
+ try {
74
+ return (0, path_filter_1.matchPathFilter)(pathFilter, req.url, req);
75
+ }
76
+ catch (err) {
77
+ (0, debug_1.Debug)('Error: matchPathFilter() called with request url: ', `"${req.url}"`);
78
+ this.logger.error(err);
79
+ return false;
80
+ }
73
81
  };
74
82
  /**
75
83
  * Apply option.router and option.pathRewrite
@@ -122,6 +130,7 @@ class HttpProxyMiddleware {
122
130
  };
123
131
  (0, configuration_1.verifyConfig)(options);
124
132
  this.proxyOptions = options;
133
+ this.logger = (0, logger_1.getLogger)(options);
125
134
  (0, debug_1.Debug)(`create proxy server`);
126
135
  this.proxy = httpProxy.createProxyServer({});
127
136
  this.registerPlugins(this.proxy, this.proxyOptions);
package/dist/logger.js CHANGED
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- /* eslint-disable @typescript-eslint/no-empty-function */
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.getLogger = getLogger;
5
4
  /**
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createPathRewriter = createPathRewriter;
4
- const isPlainObj = require("is-plain-obj");
4
+ const is_plain_object_1 = require("is-plain-object");
5
5
  const errors_1 = require("./errors");
6
6
  const debug_1 = require("./debug");
7
7
  const debug = debug_1.Debug.extend('path-rewriter');
@@ -40,7 +40,7 @@ function isValidRewriteConfig(rewriteConfig) {
40
40
  if (typeof rewriteConfig === 'function') {
41
41
  return true;
42
42
  }
43
- else if (isPlainObj(rewriteConfig)) {
43
+ else if ((0, is_plain_object_1.isPlainObject)(rewriteConfig)) {
44
44
  return Object.keys(rewriteConfig).length !== 0;
45
45
  }
46
46
  else if (rewriteConfig === undefined || rewriteConfig === null) {
@@ -52,7 +52,7 @@ function isValidRewriteConfig(rewriteConfig) {
52
52
  }
53
53
  function parsePathRewriteRules(rewriteConfig) {
54
54
  const rules = [];
55
- if (isPlainObj(rewriteConfig)) {
55
+ if ((0, is_plain_object_1.isPlainObject)(rewriteConfig)) {
56
56
  for (const [key, value] of Object.entries(rewriteConfig)) {
57
57
  rules.push({
58
58
  regex: new RegExp(key),
@@ -26,15 +26,25 @@ const loggerPlugin = (proxyServer, options) => {
26
26
  // Next.js doesn't have req.baseUrl
27
27
  const originalUrl = req.originalUrl ?? `${req.baseUrl || ''}${req.url}`;
28
28
  // construct targetUrl
29
- const port = (0, logger_plugin_1.getPort)(proxyRes.req?.agent?.sockets);
30
- const obj = {
31
- protocol: proxyRes.req.protocol,
32
- host: proxyRes.req.host,
33
- pathname: proxyRes.req.path,
34
- };
35
- const target = new url_1.URL(`${obj.protocol}//${obj.host}${obj.pathname}`);
36
- if (port) {
37
- target.port = port;
29
+ let target;
30
+ try {
31
+ const port = (0, logger_plugin_1.getPort)(proxyRes.req?.agent?.sockets);
32
+ const obj = {
33
+ protocol: proxyRes.req.protocol,
34
+ host: proxyRes.req.host,
35
+ pathname: proxyRes.req.path,
36
+ };
37
+ target = new url_1.URL(`${obj.protocol}//${obj.host}${obj.pathname}`);
38
+ if (port) {
39
+ target.port = port;
40
+ }
41
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
42
+ }
43
+ catch (err) {
44
+ // nock issue (https://github.com/chimurai/http-proxy-middleware/issues/1035)
45
+ // fallback to old implementation (less correct - without port)
46
+ target = new url_1.URL(options.target);
47
+ target.pathname = proxyRes.req.path;
38
48
  }
39
49
  const targetUrl = target.toString();
40
50
  const exchange = `[HPM] ${req.method} ${originalUrl} -> ${targetUrl} [${proxyRes.statusCode}]`;
package/dist/router.js CHANGED
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getTarget = getTarget;
4
- const isPlainObj = require("is-plain-obj");
4
+ const is_plain_object_1 = require("is-plain-object");
5
5
  const debug_1 = require("./debug");
6
6
  const debug = debug_1.Debug.extend('router');
7
7
  async function getTarget(req, config) {
8
8
  let newTarget;
9
9
  const router = config.router;
10
- if (isPlainObj(router)) {
10
+ if ((0, is_plain_object_1.isPlainObject)(router)) {
11
11
  newTarget = getTargetFromProxyTable(req, router);
12
12
  }
13
13
  else if (typeof router === 'function') {
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- /* eslint-disable @typescript-eslint/ban-types */
2
+ /* eslint-disable @typescript-eslint/no-unsafe-function-type */
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.getFunctionName = getFunctionName;
5
5
  function getFunctionName(fn) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "http-proxy-middleware",
3
3
  "type": "commonjs",
4
- "version": "3.0.1",
4
+ "version": "3.0.3",
5
5
  "description": "The one-liner node.js proxy middleware for connect, express, next.js and more",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -13,7 +13,7 @@
13
13
  "install:all": "yarn && (cd examples && yarn)",
14
14
  "lint": "yarn prettier && yarn eslint",
15
15
  "lint:fix": "yarn prettier:fix && yarn eslint:fix",
16
- "eslint": "eslint '{src,test}/**/*.ts' --cache",
16
+ "eslint": "eslint '{src,test,examples}/**/*.{js,ts}' --cache",
17
17
  "eslint:fix": "yarn eslint --fix",
18
18
  "prettier": "prettier --list-different \"**/*.{js,ts,md,yml,json,html}\"",
19
19
  "prettier:fix": "prettier --write \"**/*.{js,ts,md,yml,json,html}\"",
@@ -58,7 +58,10 @@
58
58
  "devDependencies": {
59
59
  "@commitlint/cli": "19.4.1",
60
60
  "@commitlint/config-conventional": "19.4.1",
61
+ "@eslint/js": "9.9.1",
61
62
  "@types/debug": "4.1.12",
63
+ "@types/eslint": "9.6.1",
64
+ "@types/eslint__js": "8.42.3",
62
65
  "@types/express": "4.17.21",
63
66
  "@types/is-glob": "4.0.4",
64
67
  "@types/jest": "29.5.12",
@@ -66,14 +69,13 @@
66
69
  "@types/node": "22.5.1",
67
70
  "@types/supertest": "6.0.2",
68
71
  "@types/ws": "8.5.12",
69
- "@typescript-eslint/eslint-plugin": "7.16.0",
70
- "@typescript-eslint/parser": "7.16.0",
71
72
  "body-parser": "1.20.2",
72
- "eslint": "8.57.0",
73
+ "eslint": "9.9.1",
73
74
  "eslint-config-prettier": "9.1.0",
74
75
  "eslint-plugin-prettier": "5.2.1",
75
76
  "express": "4.19.2",
76
77
  "get-port": "5.1.1",
78
+ "globals": "15.9.0",
77
79
  "husky": "9.1.5",
78
80
  "jest": "29.7.0",
79
81
  "lint-staged": "15.2.9",
@@ -83,6 +85,7 @@
83
85
  "supertest": "7.0.0",
84
86
  "ts-jest": "29.2.5",
85
87
  "typescript": "5.5.4",
88
+ "typescript-eslint": "8.3.0",
86
89
  "ws": "8.18.0"
87
90
  },
88
91
  "dependencies": {
@@ -90,7 +93,7 @@
90
93
  "debug": "^4.3.6",
91
94
  "http-proxy": "^1.18.1",
92
95
  "is-glob": "^4.0.3",
93
- "is-plain-obj": "^3.0.0",
96
+ "is-plain-object": "^5.0.0",
94
97
  "micromatch": "^4.0.8"
95
98
  },
96
99
  "engines": {