http-proxy-middleware 4.0.0-beta.0 → 4.0.0-beta.2
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 +39 -39
- package/dist/configuration.d.ts +3 -2
- package/dist/configuration.js +3 -6
- package/dist/debug.d.ts +1 -1
- package/dist/debug.js +2 -5
- package/dist/errors.js +2 -5
- package/dist/factory.d.ts +2 -2
- package/dist/factory.js +3 -6
- package/dist/get-plugins.d.ts +3 -2
- package/dist/get-plugins.js +4 -7
- package/dist/handlers/fix-request-body.js +18 -7
- package/dist/handlers/index.d.ts +1 -1
- package/dist/handlers/index.js +1 -17
- package/dist/handlers/public.d.ts +2 -2
- package/dist/handlers/public.js +2 -7
- package/dist/handlers/response-interceptor.js +6 -9
- package/dist/http-proxy-middleware.d.ts +4 -3
- package/dist/http-proxy-middleware.js +30 -41
- package/dist/index.d.ts +4 -8
- package/dist/index.js +3 -23
- package/dist/logger.d.ts +1 -1
- package/dist/logger.js +1 -4
- package/dist/path-filter.d.ts +2 -2
- package/dist/path-filter.js +7 -11
- package/dist/path-rewriter.js +8 -11
- package/dist/plugins/default/debug-proxy-errors-plugin.d.ts +1 -1
- package/dist/plugins/default/debug-proxy-errors-plugin.js +3 -7
- package/dist/plugins/default/error-response-plugin.d.ts +1 -1
- package/dist/plugins/default/error-response-plugin.js +5 -9
- package/dist/plugins/default/index.d.ts +4 -4
- package/dist/plugins/default/index.js +4 -20
- package/dist/plugins/default/logger-plugin.d.ts +1 -1
- package/dist/plugins/default/logger-plugin.js +8 -12
- package/dist/plugins/default/proxy-events.d.ts +1 -1
- package/dist/plugins/default/proxy-events.js +5 -9
- package/dist/router.js +5 -8
- package/dist/status-code.js +1 -4
- package/dist/types.d.ts +5 -5
- package/dist/types.js +1 -2
- package/dist/utils/function.js +1 -4
- package/dist/utils/logger-plugin.js +1 -4
- package/dist/utils/sanitize.js +1 -4
- package/package.json +19 -12
- package/dist/legacy/create-proxy-middleware.d.ts +0 -12
- package/dist/legacy/create-proxy-middleware.js +0 -16
- package/dist/legacy/index.d.ts +0 -1
- package/dist/legacy/index.js +0 -17
- package/dist/legacy/options-adapter.d.ts +0 -6
- package/dist/legacy/options-adapter.js +0 -97
- package/dist/legacy/public.d.ts +0 -2
- package/dist/legacy/public.js +0 -5
- package/dist/legacy/types.d.ts +0 -111
- package/dist/legacy/types.js +0 -2
package/dist/index.js
CHANGED
|
@@ -1,26 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./factory"), exports);
|
|
18
|
-
__exportStar(require("./handlers"), exports);
|
|
1
|
+
export * from './factory.js';
|
|
2
|
+
export * from './handlers/index.js';
|
|
19
3
|
/**
|
|
20
4
|
* Default plugins
|
|
21
5
|
*/
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Legacy exports
|
|
25
|
-
*/
|
|
26
|
-
__exportStar(require("./legacy"), exports);
|
|
6
|
+
export * from './plugins/default/index.js';
|
package/dist/logger.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Logger, Options } from './types';
|
|
1
|
+
import { Logger, Options } from './types.js';
|
|
2
2
|
export declare function getLogger(options: Options): Logger;
|
package/dist/logger.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getLogger = getLogger;
|
|
4
1
|
/**
|
|
5
2
|
* Compatibility matrix
|
|
6
3
|
*
|
|
@@ -19,6 +16,6 @@ const noopLogger = {
|
|
|
19
16
|
warn: () => { },
|
|
20
17
|
error: () => { },
|
|
21
18
|
};
|
|
22
|
-
function getLogger(options) {
|
|
19
|
+
export function getLogger(options) {
|
|
23
20
|
return options.logger || noopLogger;
|
|
24
21
|
}
|
package/dist/path-filter.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type * as http from 'node:http';
|
|
2
|
-
import type { Filter } from './types';
|
|
3
|
-
export declare function matchPathFilter<TReq = http.IncomingMessage>(pathFilter: Filter<TReq> | undefined, uri: string | undefined, req: http.IncomingMessage): boolean;
|
|
2
|
+
import type { Filter } from './types.js';
|
|
3
|
+
export declare function matchPathFilter<TReq extends http.IncomingMessage = http.IncomingMessage>(pathFilter: Filter<TReq> | undefined, uri: string | undefined, req: http.IncomingMessage): boolean;
|
package/dist/path-filter.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const isGlob = require("is-glob");
|
|
6
|
-
const micromatch = require("micromatch");
|
|
7
|
-
const errors_1 = require("./errors");
|
|
8
|
-
function matchPathFilter(pathFilter = '/', uri, req) {
|
|
1
|
+
import isGlob from 'is-glob';
|
|
2
|
+
import micromatch from 'micromatch';
|
|
3
|
+
import { ERRORS } from './errors.js';
|
|
4
|
+
export function matchPathFilter(pathFilter = '/', uri, req) {
|
|
9
5
|
// single path
|
|
10
6
|
if (isStringPath(pathFilter)) {
|
|
11
7
|
return matchSingleStringPath(pathFilter, uri);
|
|
@@ -22,14 +18,14 @@ function matchPathFilter(pathFilter = '/', uri, req) {
|
|
|
22
18
|
if (pathFilter.every(isGlobPath)) {
|
|
23
19
|
return matchMultiGlobPath(pathFilter, uri);
|
|
24
20
|
}
|
|
25
|
-
throw new Error(
|
|
21
|
+
throw new Error(ERRORS.ERR_CONTEXT_MATCHER_INVALID_ARRAY);
|
|
26
22
|
}
|
|
27
23
|
// custom matching
|
|
28
24
|
if (typeof pathFilter === 'function') {
|
|
29
25
|
const pathname = getUrlPathName(uri);
|
|
30
26
|
return pathFilter(pathname, req);
|
|
31
27
|
}
|
|
32
|
-
throw new Error(
|
|
28
|
+
throw new Error(ERRORS.ERR_CONTEXT_MATCHER_GENERIC);
|
|
33
29
|
}
|
|
34
30
|
/**
|
|
35
31
|
* @param {String} pathFilter '/api'
|
|
@@ -70,7 +66,7 @@ function matchMultiPath(pathFilterList, uri) {
|
|
|
70
66
|
* @return {String} RFC 3986 path
|
|
71
67
|
*/
|
|
72
68
|
function getUrlPathName(uri) {
|
|
73
|
-
return uri &&
|
|
69
|
+
return uri && new URL(uri, 'http://0.0.0.0').pathname;
|
|
74
70
|
}
|
|
75
71
|
function isStringPath(pathFilter) {
|
|
76
72
|
return typeof pathFilter === 'string' && !isGlob(pathFilter);
|
package/dist/path-rewriter.js
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const debug_1 = require("./debug");
|
|
6
|
-
const errors_1 = require("./errors");
|
|
7
|
-
const debug = debug_1.Debug.extend('path-rewriter');
|
|
1
|
+
import { isPlainObject } from 'is-plain-object';
|
|
2
|
+
import { Debug } from './debug.js';
|
|
3
|
+
import { ERRORS } from './errors.js';
|
|
4
|
+
const debug = Debug.extend('path-rewriter');
|
|
8
5
|
/**
|
|
9
6
|
* Create rewrite function, to cache parsed rewrite rules.
|
|
10
7
|
*
|
|
11
8
|
* @param {Object} rewriteConfig
|
|
12
9
|
* @return {Function} Function to rewrite paths; This function should accept `path` (request.url) as parameter
|
|
13
10
|
*/
|
|
14
|
-
function createPathRewriter(rewriteConfig) {
|
|
11
|
+
export function createPathRewriter(rewriteConfig) {
|
|
15
12
|
let rulesCache;
|
|
16
13
|
if (!isValidRewriteConfig(rewriteConfig)) {
|
|
17
14
|
return;
|
|
@@ -40,19 +37,19 @@ function isValidRewriteConfig(rewriteConfig) {
|
|
|
40
37
|
if (typeof rewriteConfig === 'function') {
|
|
41
38
|
return true;
|
|
42
39
|
}
|
|
43
|
-
else if (
|
|
40
|
+
else if (isPlainObject(rewriteConfig)) {
|
|
44
41
|
return Object.keys(rewriteConfig).length !== 0;
|
|
45
42
|
}
|
|
46
43
|
else if (rewriteConfig === undefined || rewriteConfig === null) {
|
|
47
44
|
return false;
|
|
48
45
|
}
|
|
49
46
|
else {
|
|
50
|
-
throw new Error(
|
|
47
|
+
throw new Error(ERRORS.ERR_PATH_REWRITER_CONFIG);
|
|
51
48
|
}
|
|
52
49
|
}
|
|
53
50
|
function parsePathRewriteRules(rewriteConfig) {
|
|
54
51
|
const rules = [];
|
|
55
|
-
if (
|
|
52
|
+
if (isPlainObject(rewriteConfig)) {
|
|
56
53
|
for (const [key, value] of Object.entries(rewriteConfig)) {
|
|
57
54
|
rules.push({
|
|
58
55
|
regex: new RegExp(key),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Plugin } from '../../types';
|
|
1
|
+
import { Plugin } from '../../types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Subscribe to {@link https://www.npmjs.com/package/http-proxy#listening-for-proxy-events http-proxy error events} to prevent server from crashing.
|
|
4
4
|
* Errors are logged with {@link https://www.npmjs.com/package/debug debug} library.
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.debugProxyErrorsPlugin = void 0;
|
|
4
|
-
const debug_1 = require("../../debug");
|
|
5
|
-
const debug = debug_1.Debug.extend('debug-proxy-errors-plugin');
|
|
1
|
+
import { Debug } from '../../debug.js';
|
|
2
|
+
const debug = Debug.extend('debug-proxy-errors-plugin');
|
|
6
3
|
/**
|
|
7
4
|
* Subscribe to {@link https://www.npmjs.com/package/http-proxy#listening-for-proxy-events http-proxy error events} to prevent server from crashing.
|
|
8
5
|
* Errors are logged with {@link https://www.npmjs.com/package/debug debug} library.
|
|
9
6
|
*/
|
|
10
|
-
const debugProxyErrorsPlugin = (proxyServer) => {
|
|
7
|
+
export const debugProxyErrorsPlugin = (proxyServer) => {
|
|
11
8
|
/**
|
|
12
9
|
* http-proxy doesn't handle any errors by default (https://github.com/http-party/node-http-proxy#listening-for-proxy-events)
|
|
13
10
|
* Prevent server from crashing when http-proxy errors (uncaught errors)
|
|
@@ -58,4 +55,3 @@ const debugProxyErrorsPlugin = (proxyServer) => {
|
|
|
58
55
|
debug(`http-proxy econnreset event: \n%O`, error);
|
|
59
56
|
});
|
|
60
57
|
};
|
|
61
|
-
exports.debugProxyErrorsPlugin = debugProxyErrorsPlugin;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Plugin } from '../../types';
|
|
1
|
+
import { Plugin } from '../../types.js';
|
|
2
2
|
export declare const errorResponsePlugin: Plugin;
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.errorResponsePlugin = void 0;
|
|
4
|
-
const status_code_1 = require("../../status-code");
|
|
5
|
-
const sanitize_1 = require("../../utils/sanitize");
|
|
1
|
+
import { getStatusCode } from '../../status-code.js';
|
|
2
|
+
import { sanitize } from '../../utils/sanitize.js';
|
|
6
3
|
function isResponseLike(obj) {
|
|
7
4
|
return obj && typeof obj.writeHead === 'function';
|
|
8
5
|
}
|
|
9
6
|
function isSocketLike(obj) {
|
|
10
7
|
return obj && typeof obj.write === 'function' && !('writeHead' in obj);
|
|
11
8
|
}
|
|
12
|
-
const errorResponsePlugin = (proxyServer, options) => {
|
|
9
|
+
export const errorResponsePlugin = (proxyServer, options) => {
|
|
13
10
|
proxyServer.on('error', (err, req, res, target) => {
|
|
14
11
|
// Re-throw error. Not recoverable since req & res are empty.
|
|
15
12
|
if (!req || !res) {
|
|
@@ -17,15 +14,14 @@ const errorResponsePlugin = (proxyServer, options) => {
|
|
|
17
14
|
}
|
|
18
15
|
if (isResponseLike(res)) {
|
|
19
16
|
if (!res.headersSent) {
|
|
20
|
-
const statusCode =
|
|
17
|
+
const statusCode = getStatusCode(err.code);
|
|
21
18
|
res.writeHead(statusCode);
|
|
22
19
|
}
|
|
23
20
|
const host = req.headers && req.headers.host;
|
|
24
|
-
res.end(`Error occurred while trying to proxy: ${
|
|
21
|
+
res.end(`Error occurred while trying to proxy: ${sanitize(host)}${sanitize(req.url)}`);
|
|
25
22
|
}
|
|
26
23
|
else if (isSocketLike(res)) {
|
|
27
24
|
res.destroy();
|
|
28
25
|
}
|
|
29
26
|
});
|
|
30
27
|
};
|
|
31
|
-
exports.errorResponsePlugin = errorResponsePlugin;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './debug-proxy-errors-plugin';
|
|
2
|
-
export * from './error-response-plugin';
|
|
3
|
-
export * from './logger-plugin';
|
|
4
|
-
export * from './proxy-events';
|
|
1
|
+
export * from './debug-proxy-errors-plugin.js';
|
|
2
|
+
export * from './error-response-plugin.js';
|
|
3
|
+
export * from './logger-plugin.js';
|
|
4
|
+
export * from './proxy-events.js';
|
|
@@ -1,20 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./debug-proxy-errors-plugin"), exports);
|
|
18
|
-
__exportStar(require("./error-response-plugin"), exports);
|
|
19
|
-
__exportStar(require("./logger-plugin"), exports);
|
|
20
|
-
__exportStar(require("./proxy-events"), exports);
|
|
1
|
+
export * from './debug-proxy-errors-plugin.js';
|
|
2
|
+
export * from './error-response-plugin.js';
|
|
3
|
+
export * from './logger-plugin.js';
|
|
4
|
+
export * from './proxy-events.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Plugin } from '../../types';
|
|
1
|
+
import { Plugin } from '../../types.js';
|
|
2
2
|
export declare const loggerPlugin: Plugin;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const logger_plugin_1 = require("../../utils/logger-plugin");
|
|
7
|
-
const loggerPlugin = (proxyServer, options) => {
|
|
8
|
-
const logger = (0, logger_1.getLogger)(options);
|
|
1
|
+
import { URL } from 'node:url';
|
|
2
|
+
import { getLogger } from '../../logger.js';
|
|
3
|
+
import { getPort } from '../../utils/logger-plugin.js';
|
|
4
|
+
export const loggerPlugin = (proxyServer, options) => {
|
|
5
|
+
const logger = getLogger(options);
|
|
9
6
|
proxyServer.on('error', (err, req, res, target) => {
|
|
10
7
|
const hostname = req?.headers?.host;
|
|
11
8
|
const requestHref = `${hostname}${req?.url}`;
|
|
@@ -28,13 +25,13 @@ const loggerPlugin = (proxyServer, options) => {
|
|
|
28
25
|
// construct targetUrl
|
|
29
26
|
let target;
|
|
30
27
|
try {
|
|
31
|
-
const port =
|
|
28
|
+
const port = getPort(proxyRes.req?.agent?.sockets);
|
|
32
29
|
const obj = {
|
|
33
30
|
protocol: proxyRes.req.protocol,
|
|
34
31
|
host: proxyRes.req.host,
|
|
35
32
|
pathname: proxyRes.req.path,
|
|
36
33
|
};
|
|
37
|
-
target = new
|
|
34
|
+
target = new URL(`${obj.protocol}//${obj.host}${obj.pathname}`);
|
|
38
35
|
if (port) {
|
|
39
36
|
target.port = port;
|
|
40
37
|
}
|
|
@@ -43,7 +40,7 @@ const loggerPlugin = (proxyServer, options) => {
|
|
|
43
40
|
catch (err) {
|
|
44
41
|
// nock issue (https://github.com/chimurai/http-proxy-middleware/issues/1035)
|
|
45
42
|
// fallback to old implementation (less correct - without port)
|
|
46
|
-
target = new
|
|
43
|
+
target = new URL(options.target);
|
|
47
44
|
target.pathname = proxyRes.req.path;
|
|
48
45
|
}
|
|
49
46
|
const targetUrl = target.toString();
|
|
@@ -63,4 +60,3 @@ const loggerPlugin = (proxyServer, options) => {
|
|
|
63
60
|
logger.info('[HPM] Client disconnected: %o', proxySocket.address());
|
|
64
61
|
});
|
|
65
62
|
};
|
|
66
|
-
exports.loggerPlugin = loggerPlugin;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const debug_1 = require("../../debug");
|
|
5
|
-
const function_1 = require("../../utils/function");
|
|
6
|
-
const debug = debug_1.Debug.extend('proxy-events-plugin');
|
|
1
|
+
import { Debug } from '../../debug.js';
|
|
2
|
+
import { getFunctionName } from '../../utils/function.js';
|
|
3
|
+
const debug = Debug.extend('proxy-events-plugin');
|
|
7
4
|
/**
|
|
8
5
|
* Implements option.on object to subscribe to http-proxy events.
|
|
9
6
|
*
|
|
@@ -24,7 +21,7 @@ const debug = debug_1.Debug.extend('proxy-events-plugin');
|
|
|
24
21
|
* });
|
|
25
22
|
* ```
|
|
26
23
|
*/
|
|
27
|
-
const proxyEventsPlugin = (proxyServer, options) => {
|
|
24
|
+
export const proxyEventsPlugin = (proxyServer, options) => {
|
|
28
25
|
if (!options.on) {
|
|
29
26
|
return;
|
|
30
27
|
}
|
|
@@ -37,9 +34,8 @@ const proxyEventsPlugin = (proxyServer, options) => {
|
|
|
37
34
|
if (!handler) {
|
|
38
35
|
continue;
|
|
39
36
|
}
|
|
40
|
-
debug(`register event handler: "${eventName}" -> "${
|
|
37
|
+
debug(`register event handler: "${eventName}" -> "${getFunctionName(handler)}"`);
|
|
41
38
|
proxyServer.on(eventName, handler);
|
|
42
39
|
}
|
|
43
40
|
}
|
|
44
41
|
};
|
|
45
|
-
exports.proxyEventsPlugin = proxyEventsPlugin;
|
package/dist/router.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const debug_1 = require("./debug");
|
|
6
|
-
const debug = debug_1.Debug.extend('router');
|
|
7
|
-
async function getTarget(req, config) {
|
|
1
|
+
import { isPlainObject } from 'is-plain-object';
|
|
2
|
+
import { Debug } from './debug.js';
|
|
3
|
+
const debug = Debug.extend('router');
|
|
4
|
+
export async function getTarget(req, config) {
|
|
8
5
|
let newTarget;
|
|
9
6
|
const router = config.router;
|
|
10
|
-
if (
|
|
7
|
+
if (isPlainObject(router)) {
|
|
11
8
|
newTarget = getTargetFromProxyTable(req, router);
|
|
12
9
|
}
|
|
13
10
|
else if (typeof router === 'function') {
|
package/dist/status-code.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getStatusCode = getStatusCode;
|
|
4
|
-
function getStatusCode(errorCode) {
|
|
1
|
+
export function getStatusCode(errorCode) {
|
|
5
2
|
let statusCode;
|
|
6
3
|
if (/HPE_INVALID/.test(errorCode)) {
|
|
7
4
|
statusCode = 502;
|
package/dist/types.d.ts
CHANGED
|
@@ -6,15 +6,15 @@ import type * as http from 'node:http';
|
|
|
6
6
|
import type * as net from 'node:net';
|
|
7
7
|
import type { ProxyServer, ProxyServerOptions } from 'httpxy';
|
|
8
8
|
export type NextFunction<T = (err?: any) => void> = T;
|
|
9
|
-
export interface RequestHandler<TReq = http.IncomingMessage, TRes = http.ServerResponse, TNext = NextFunction> {
|
|
9
|
+
export interface RequestHandler<TReq extends http.IncomingMessage = http.IncomingMessage, TRes extends http.ServerResponse = http.ServerResponse, TNext = NextFunction> {
|
|
10
10
|
(req: TReq, res: TRes, next?: TNext): Promise<void>;
|
|
11
11
|
upgrade: (req: http.IncomingMessage, socket: net.Socket, head: Buffer) => void;
|
|
12
12
|
}
|
|
13
|
-
export type Filter<TReq = http.IncomingMessage> = string | string[] | ((pathname: string, req: TReq) => boolean);
|
|
14
|
-
export interface Plugin<TReq = http.IncomingMessage, TRes = http.ServerResponse> {
|
|
13
|
+
export type Filter<TReq extends http.IncomingMessage = http.IncomingMessage> = string | string[] | ((pathname: string, req: TReq) => boolean);
|
|
14
|
+
export interface Plugin<TReq extends http.IncomingMessage = http.IncomingMessage, TRes extends http.ServerResponse = http.ServerResponse> {
|
|
15
15
|
(proxyServer: ProxyServer<TReq, TRes>, options: Options<TReq, TRes>): void;
|
|
16
16
|
}
|
|
17
|
-
export interface OnProxyEvent<TReq = http.IncomingMessage, TRes = http.ServerResponse> {
|
|
17
|
+
export interface OnProxyEvent<TReq extends http.IncomingMessage = http.IncomingMessage, TRes extends http.ServerResponse = http.ServerResponse> {
|
|
18
18
|
error?: (err: Error, req: TReq, res: TRes | net.Socket, target?: string | Partial<URL>) => void;
|
|
19
19
|
proxyReq?: (proxyReq: http.ClientRequest, req: TReq, res: TRes, options: ProxyServerOptions) => void;
|
|
20
20
|
proxyReqWs?: (proxyReq: http.ClientRequest, req: TReq, socket: net.Socket, options: ProxyServerOptions, head: any) => void;
|
|
@@ -26,7 +26,7 @@ export interface OnProxyEvent<TReq = http.IncomingMessage, TRes = http.ServerRes
|
|
|
26
26
|
econnreset?: (err: Error, req: TReq, res: TRes, target: string | Partial<URL>) => void;
|
|
27
27
|
}
|
|
28
28
|
export type Logger = Pick<Console, 'info' | 'warn' | 'error'>;
|
|
29
|
-
export interface Options<TReq = http.IncomingMessage, TRes = http.ServerResponse> extends ProxyServerOptions {
|
|
29
|
+
export interface Options<TReq extends http.IncomingMessage = http.IncomingMessage, TRes extends http.ServerResponse = http.ServerResponse> extends ProxyServerOptions {
|
|
30
30
|
/**
|
|
31
31
|
* Narrow down requests to proxy or not.
|
|
32
32
|
* Filter on {@link http.IncomingMessage.url `pathname`} which is relative to the proxy's "mounting" point in the server.
|
package/dist/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/dist/utils/function.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/* eslint-disable @typescript-eslint/no-unsafe-function-type */
|
|
3
|
-
|
|
4
|
-
exports.getFunctionName = getFunctionName;
|
|
5
|
-
function getFunctionName(fn) {
|
|
2
|
+
export function getFunctionName(fn) {
|
|
6
3
|
return fn.name || '[anonymous Function]';
|
|
7
4
|
}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPort = getPort;
|
|
4
1
|
/**
|
|
5
2
|
* Get port from target
|
|
6
3
|
* Using proxyRes.req.agent.sockets to determine the target port
|
|
7
4
|
*/
|
|
8
|
-
function getPort(sockets) {
|
|
5
|
+
export function getPort(sockets) {
|
|
9
6
|
return Object.keys(sockets || {})?.[0]?.split(':')[1];
|
|
10
7
|
}
|
package/dist/utils/sanitize.js
CHANGED
package/package.json
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "http-proxy-middleware",
|
|
3
|
-
"type": "
|
|
4
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "4.0.0-beta.2",
|
|
5
5
|
"description": "The one-liner node.js proxy middleware for connect, express, next.js and more",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
7
14
|
"types": "dist/index.d.ts",
|
|
8
15
|
"files": [
|
|
9
16
|
"dist"
|
|
@@ -13,13 +20,14 @@
|
|
|
13
20
|
"install:all": "yarn && (cd examples && yarn)",
|
|
14
21
|
"lint": "yarn prettier && yarn eslint",
|
|
15
22
|
"lint:fix": "yarn prettier:fix && yarn eslint:fix",
|
|
16
|
-
"eslint": "eslint '{
|
|
23
|
+
"eslint": "eslint --cache '**/*.{js,ts,mjs,mts}'",
|
|
17
24
|
"eslint:fix": "yarn eslint --fix",
|
|
18
|
-
"prettier": "prettier --list-different \"**/*.{js,ts,md,yml,json,html}\"",
|
|
19
|
-
"prettier:fix": "prettier --write \"**/*.{js,ts,md,yml,json,html}\"",
|
|
25
|
+
"prettier": "prettier --list-different \"**/*.{js,ts,mjs,mts,md,yml,json,html}\"",
|
|
26
|
+
"prettier:fix": "prettier --write \"**/*.{js,ts,mjs,mts,md,yml,json,html}\"",
|
|
20
27
|
"build": "tsc --build",
|
|
21
|
-
"test": "
|
|
22
|
-
"
|
|
28
|
+
"test": "vitest run",
|
|
29
|
+
"test:types": "tsc --project tsconfig.test.json --noEmit",
|
|
30
|
+
"coverage": "vitest run --coverage",
|
|
23
31
|
"prepare": "husky && patch-package",
|
|
24
32
|
"prepack": "yarn clean && yarn test && yarn build",
|
|
25
33
|
"spellcheck": "npx --yes cspell --show-context --show-suggestions '**/*.*'"
|
|
@@ -64,18 +72,17 @@
|
|
|
64
72
|
"@types/eslint": "9.6.1",
|
|
65
73
|
"@types/express": "5.0.6",
|
|
66
74
|
"@types/is-glob": "4.0.4",
|
|
67
|
-
"@types/jest": "30.0.0",
|
|
68
75
|
"@types/micromatch": "4.0.10",
|
|
69
76
|
"@types/node": "24.10.2",
|
|
70
77
|
"@types/supertest": "7.2.0",
|
|
71
78
|
"@types/ws": "8.18.1",
|
|
79
|
+
"@vitest/coverage-v8": "^4.1.2",
|
|
72
80
|
"body-parser": "2.2.2",
|
|
73
81
|
"eslint": "10.0.2",
|
|
74
82
|
"express": "5.2.1",
|
|
75
83
|
"get-port": "5.1.1",
|
|
76
84
|
"globals": "17.3.0",
|
|
77
85
|
"husky": "9.1.7",
|
|
78
|
-
"jest": "30.2.0",
|
|
79
86
|
"lint-staged": "16.3.0",
|
|
80
87
|
"mockttp": "4.2.1",
|
|
81
88
|
"open": "8.4.2",
|
|
@@ -83,14 +90,14 @@
|
|
|
83
90
|
"pkg-pr-new": "0.0.65",
|
|
84
91
|
"prettier": "3.8.1",
|
|
85
92
|
"supertest": "7.2.2",
|
|
86
|
-
"ts-jest": "29.4.6",
|
|
87
93
|
"typescript": "5.9.3",
|
|
88
94
|
"typescript-eslint": "8.56.1",
|
|
95
|
+
"vitest": "^4.1.2",
|
|
89
96
|
"ws": "8.19.0"
|
|
90
97
|
},
|
|
91
98
|
"dependencies": {
|
|
92
99
|
"debug": "^4.3.6",
|
|
93
|
-
"httpxy": "^0.
|
|
100
|
+
"httpxy": "^0.5.0",
|
|
94
101
|
"is-glob": "^4.0.3",
|
|
95
102
|
"is-plain-object": "^5.0.0",
|
|
96
103
|
"micromatch": "^4.0.8"
|
|
@@ -99,7 +106,7 @@
|
|
|
99
106
|
"patch-package/**/tmp": "^0.2.4"
|
|
100
107
|
},
|
|
101
108
|
"engines": {
|
|
102
|
-
"node": ">=
|
|
109
|
+
"node": "^22.12.0 || >=24.0.0"
|
|
103
110
|
},
|
|
104
111
|
"commitlint": {
|
|
105
112
|
"extends": [
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type * as http from 'node:http';
|
|
2
|
-
import { Filter, RequestHandler } from '../types';
|
|
3
|
-
import { LegacyOptions } from './types';
|
|
4
|
-
/**
|
|
5
|
-
* @deprecated
|
|
6
|
-
* This function is deprecated and will be removed in a future version.
|
|
7
|
-
*
|
|
8
|
-
* Use {@link createProxyMiddleware} instead.
|
|
9
|
-
*/
|
|
10
|
-
export declare function legacyCreateProxyMiddleware<TReq = http.IncomingMessage, TRes = http.ServerResponse>(shortHand: string): RequestHandler<TReq, TRes>;
|
|
11
|
-
export declare function legacyCreateProxyMiddleware<TReq = http.IncomingMessage, TRes = http.ServerResponse>(legacyOptions: LegacyOptions<TReq, TRes>): RequestHandler<TReq, TRes>;
|
|
12
|
-
export declare function legacyCreateProxyMiddleware<TReq = http.IncomingMessage, TRes = http.ServerResponse>(legacyContext: Filter<TReq>, legacyOptions: LegacyOptions<TReq, TRes>): RequestHandler<TReq, TRes>;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.legacyCreateProxyMiddleware = legacyCreateProxyMiddleware;
|
|
4
|
-
const debug_1 = require("../debug");
|
|
5
|
-
const factory_1 = require("../factory");
|
|
6
|
-
const options_adapter_1 = require("./options-adapter");
|
|
7
|
-
const debug = debug_1.Debug.extend('legacy-create-proxy-middleware');
|
|
8
|
-
function legacyCreateProxyMiddleware(legacyContext, legacyOptions) {
|
|
9
|
-
debug('init');
|
|
10
|
-
const options = (0, options_adapter_1.legacyOptionsAdapter)(legacyContext, legacyOptions);
|
|
11
|
-
const proxyMiddleware = (0, factory_1.createProxyMiddleware)(options);
|
|
12
|
-
// https://github.com/chimurai/http-proxy-middleware/pull/731/files#diff-07e6ad10bda0df091b737caed42767657cd0bd74a01246a1a0b7ab59c0f6e977L118
|
|
13
|
-
debug('add marker for patching req.url (old behavior)');
|
|
14
|
-
proxyMiddleware.__LEGACY_HTTP_PROXY_MIDDLEWARE__ = true;
|
|
15
|
-
return proxyMiddleware;
|
|
16
|
-
}
|
package/dist/legacy/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './public';
|
package/dist/legacy/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./public"), exports);
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Filter, Options } from '../types';
|
|
2
|
-
import { LegacyOptions } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* Convert {@link LegacyOptions legacy Options} to new {@link Options}
|
|
5
|
-
*/
|
|
6
|
-
export declare function legacyOptionsAdapter<TReq, TRes>(legacyContext: Filter<TReq> | LegacyOptions<TReq, TRes>, legacyOptions: LegacyOptions<TReq, TRes>): Options<TReq, TRes>;
|