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.
- package/dist/get-plugins.js +2 -2
- package/dist/http-proxy-middleware.d.ts +1 -0
- package/dist/http-proxy-middleware.js +12 -3
- package/dist/logger.js +0 -1
- package/dist/path-rewriter.js +3 -3
- package/dist/plugins/default/logger-plugin.js +19 -9
- package/dist/router.js +2 -2
- package/dist/utils/function.js +1 -1
- package/package.json +9 -6
package/dist/get-plugins.js
CHANGED
|
@@ -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 =
|
|
8
|
-
const defaultPlugins =
|
|
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 ?? [];
|
|
@@ -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
|
|
26
|
+
next?.(err);
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
else {
|
|
29
|
-
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
|
-
|
|
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
package/dist/path-rewriter.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createPathRewriter = createPathRewriter;
|
|
4
|
-
const
|
|
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 (
|
|
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 (
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
target
|
|
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
|
|
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 (
|
|
10
|
+
if ((0, is_plain_object_1.isPlainObject)(router)) {
|
|
11
11
|
newTarget = getTargetFromProxyTable(req, router);
|
|
12
12
|
}
|
|
13
13
|
else if (typeof router === 'function') {
|
package/dist/utils/function.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/* eslint-disable @typescript-eslint/
|
|
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.
|
|
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": "
|
|
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-
|
|
96
|
+
"is-plain-object": "^5.0.0",
|
|
94
97
|
"micromatch": "^4.0.8"
|
|
95
98
|
},
|
|
96
99
|
"engines": {
|