http-proxy-middleware 3.0.5 → 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 +42 -49
- 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 +3 -3
- 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.d.ts +1 -1
- package/dist/handlers/fix-request-body.js +21 -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.d.ts +3 -3
- package/dist/handlers/response-interceptor.js +6 -9
- package/dist/http-proxy-middleware.d.ts +4 -3
- package/dist/http-proxy-middleware.js +165 -140
- 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 +3 -3
- 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 +6 -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 +20 -12
- package/dist/router.js +5 -8
- package/dist/status-code.js +1 -4
- package/dist/types.d.ts +21 -21
- package/dist/types.js +1 -6
- package/dist/utils/function.js +1 -4
- package/dist/utils/logger-plugin.js +1 -4
- package/dist/utils/sanitize.d.ts +1 -0
- package/dist/utils/sanitize.js +3 -0
- package/package.json +44 -36
- 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
|
@@ -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,10 +21,21 @@ const debug = debug_1.Debug.extend('proxy-events-plugin');
|
|
|
24
21
|
* });
|
|
25
22
|
* ```
|
|
26
23
|
*/
|
|
27
|
-
const proxyEventsPlugin = (proxyServer, options) => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
24
|
+
export const proxyEventsPlugin = (proxyServer, options) => {
|
|
25
|
+
if (!options.on) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
// hoist variable here for better typing
|
|
29
|
+
let eventName;
|
|
30
|
+
// for in provide better typing than Object.entries()
|
|
31
|
+
for (eventName in options.on) {
|
|
32
|
+
if (Object.prototype.hasOwnProperty.call(options.on, eventName)) {
|
|
33
|
+
const handler = options.on[eventName];
|
|
34
|
+
if (!handler) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
debug(`register event handler: "${eventName}" -> "${getFunctionName(handler)}"`);
|
|
38
|
+
proxyServer.on(eventName, handler);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
32
41
|
};
|
|
33
|
-
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
|
@@ -2,31 +2,31 @@
|
|
|
2
2
|
* Based on definition by DefinitelyTyped:
|
|
3
3
|
* https://github.com/DefinitelyTyped/DefinitelyTyped/blob/6f529c6c67a447190f86bfbf894d1061e41e07b7/types/http-proxy-middleware/index.d.ts
|
|
4
4
|
*/
|
|
5
|
-
import type * as http from 'http';
|
|
6
|
-
import type * as
|
|
7
|
-
import type
|
|
5
|
+
import type * as http from 'node:http';
|
|
6
|
+
import type * as net from 'node:net';
|
|
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> {
|
|
15
|
-
(proxyServer:
|
|
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
|
+
(proxyServer: ProxyServer<TReq, TRes>, options: Options<TReq, TRes>): void;
|
|
16
16
|
}
|
|
17
|
-
export interface OnProxyEvent<TReq = http.IncomingMessage, TRes = http.ServerResponse> {
|
|
18
|
-
error?:
|
|
19
|
-
proxyReq?:
|
|
20
|
-
proxyReqWs?:
|
|
21
|
-
proxyRes?:
|
|
22
|
-
open?:
|
|
23
|
-
close?:
|
|
24
|
-
start?:
|
|
25
|
-
end?:
|
|
26
|
-
econnreset?:
|
|
17
|
+
export interface OnProxyEvent<TReq extends http.IncomingMessage = http.IncomingMessage, TRes extends http.ServerResponse = http.ServerResponse> {
|
|
18
|
+
error?: (err: Error, req: TReq, res: TRes | net.Socket, target?: string | Partial<URL>) => void;
|
|
19
|
+
proxyReq?: (proxyReq: http.ClientRequest, req: TReq, res: TRes, options: ProxyServerOptions) => void;
|
|
20
|
+
proxyReqWs?: (proxyReq: http.ClientRequest, req: TReq, socket: net.Socket, options: ProxyServerOptions, head: any) => void;
|
|
21
|
+
proxyRes?: (proxyRes: TReq, req: TReq, res: TRes) => void;
|
|
22
|
+
open?: (proxySocket: net.Socket) => void;
|
|
23
|
+
close?: (proxyRes: TReq, proxySocket: net.Socket, proxyHead: any) => void;
|
|
24
|
+
start?: (req: TReq, res: TRes, target: string | Partial<URL>) => void;
|
|
25
|
+
end?: (req: TReq, res: TRes, proxyRes: TReq) => void;
|
|
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
|
|
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.
|
|
@@ -105,8 +105,8 @@ export interface Options<TReq = http.IncomingMessage, TRes = http.ServerResponse
|
|
|
105
105
|
* @link https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/router.md
|
|
106
106
|
*/
|
|
107
107
|
router?: {
|
|
108
|
-
[hostOrPath: string]:
|
|
109
|
-
} | ((req: TReq) =>
|
|
108
|
+
[hostOrPath: string]: ProxyServerOptions['target'];
|
|
109
|
+
} | ((req: TReq) => ProxyServerOptions['target']) | ((req: TReq) => Promise<ProxyServerOptions['target']>);
|
|
110
110
|
/**
|
|
111
111
|
* Log information from http-proxy-middleware
|
|
112
112
|
* @example
|
|
@@ -118,5 +118,5 @@ export interface Options<TReq = http.IncomingMessage, TRes = http.ServerResponse
|
|
|
118
118
|
* @link https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/logger.md
|
|
119
119
|
* @since v3.0.0
|
|
120
120
|
*/
|
|
121
|
-
logger?: Logger
|
|
121
|
+
logger?: Logger;
|
|
122
122
|
}
|
package/dist/types.js
CHANGED
|
@@ -1,6 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Based on definition by DefinitelyTyped:
|
|
4
|
-
* https://github.com/DefinitelyTyped/DefinitelyTyped/blob/6f529c6c67a447190f86bfbf894d1061e41e07b7/types/http-proxy-middleware/index.d.ts
|
|
5
|
-
*/
|
|
6
|
-
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
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function sanitize(input: string | undefined): string;
|
package/package.json
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "http-proxy-middleware",
|
|
3
|
-
"type": "
|
|
4
|
-
"version": "
|
|
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 '**/*.*'"
|
|
@@ -56,49 +64,49 @@
|
|
|
56
64
|
},
|
|
57
65
|
"homepage": "https://github.com/chimurai/http-proxy-middleware#readme",
|
|
58
66
|
"devDependencies": {
|
|
59
|
-
"@commitlint/cli": "
|
|
60
|
-
"@commitlint/config-conventional": "
|
|
61
|
-
"@eslint/js": "
|
|
67
|
+
"@commitlint/cli": "20.4.2",
|
|
68
|
+
"@commitlint/config-conventional": "20.4.2",
|
|
69
|
+
"@eslint/js": "10.0.1",
|
|
70
|
+
"@trivago/prettier-plugin-sort-imports": "6.0.2",
|
|
62
71
|
"@types/debug": "4.1.12",
|
|
63
72
|
"@types/eslint": "9.6.1",
|
|
64
|
-
"@types/express": "
|
|
73
|
+
"@types/express": "5.0.6",
|
|
65
74
|
"@types/is-glob": "4.0.4",
|
|
66
|
-
"@types/
|
|
67
|
-
"@types/
|
|
68
|
-
"@types/
|
|
69
|
-
"@types/
|
|
70
|
-
"@
|
|
71
|
-
"body-parser": "
|
|
72
|
-
"eslint": "
|
|
73
|
-
"
|
|
74
|
-
"eslint-plugin-prettier": "5.2.3",
|
|
75
|
-
"express": "4.21.2",
|
|
75
|
+
"@types/micromatch": "4.0.10",
|
|
76
|
+
"@types/node": "24.10.2",
|
|
77
|
+
"@types/supertest": "7.2.0",
|
|
78
|
+
"@types/ws": "8.18.1",
|
|
79
|
+
"@vitest/coverage-v8": "^4.1.2",
|
|
80
|
+
"body-parser": "2.2.2",
|
|
81
|
+
"eslint": "10.0.2",
|
|
82
|
+
"express": "5.2.1",
|
|
76
83
|
"get-port": "5.1.1",
|
|
77
|
-
"globals": "
|
|
84
|
+
"globals": "17.3.0",
|
|
78
85
|
"husky": "9.1.7",
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
"mockttp": "3.17.0",
|
|
86
|
+
"lint-staged": "16.3.0",
|
|
87
|
+
"mockttp": "4.2.1",
|
|
82
88
|
"open": "8.4.2",
|
|
83
|
-
"patch-package": "8.0.
|
|
84
|
-
"pkg-pr-new": "0.0.
|
|
85
|
-
"prettier": "3.
|
|
86
|
-
"supertest": "7.
|
|
87
|
-
"
|
|
88
|
-
"typescript": "
|
|
89
|
-
"
|
|
90
|
-
"ws": "8.
|
|
89
|
+
"patch-package": "8.0.1",
|
|
90
|
+
"pkg-pr-new": "0.0.65",
|
|
91
|
+
"prettier": "3.8.1",
|
|
92
|
+
"supertest": "7.2.2",
|
|
93
|
+
"typescript": "5.9.3",
|
|
94
|
+
"typescript-eslint": "8.56.1",
|
|
95
|
+
"vitest": "^4.1.2",
|
|
96
|
+
"ws": "8.19.0"
|
|
91
97
|
},
|
|
92
98
|
"dependencies": {
|
|
93
|
-
"@types/http-proxy": "^1.17.15",
|
|
94
99
|
"debug": "^4.3.6",
|
|
95
|
-
"
|
|
100
|
+
"httpxy": "^0.5.0",
|
|
96
101
|
"is-glob": "^4.0.3",
|
|
97
102
|
"is-plain-object": "^5.0.0",
|
|
98
103
|
"micromatch": "^4.0.8"
|
|
99
104
|
},
|
|
105
|
+
"resolutions": {
|
|
106
|
+
"patch-package/**/tmp": "^0.2.4"
|
|
107
|
+
},
|
|
100
108
|
"engines": {
|
|
101
|
-
"node": "^
|
|
109
|
+
"node": "^22.12.0 || >=24.0.0"
|
|
102
110
|
},
|
|
103
111
|
"commitlint": {
|
|
104
112
|
"extends": [
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Filter, RequestHandler } from '../types';
|
|
2
|
-
import { LegacyOptions } from './types';
|
|
3
|
-
import type * as http from 'http';
|
|
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 factory_1 = require("../factory");
|
|
5
|
-
const debug_1 = require("../debug");
|
|
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>;
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.legacyOptionsAdapter = legacyOptionsAdapter;
|
|
4
|
-
const url = require("url");
|
|
5
|
-
const debug_1 = require("../debug");
|
|
6
|
-
const logger_1 = require("../logger");
|
|
7
|
-
const debug = debug_1.Debug.extend('legacy-options-adapter');
|
|
8
|
-
// https://github.com/chimurai/http-proxy-middleware/blob/7341704d0aa9d1606dfd37ebfdffddd34c894784/src/_handlers.ts#L20-L27
|
|
9
|
-
const proxyEventMap = {
|
|
10
|
-
onError: 'error',
|
|
11
|
-
onProxyReq: 'proxyReq',
|
|
12
|
-
onProxyRes: 'proxyRes',
|
|
13
|
-
onProxyReqWs: 'proxyReqWs',
|
|
14
|
-
onOpen: 'open',
|
|
15
|
-
onClose: 'close',
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* Convert {@link LegacyOptions legacy Options} to new {@link Options}
|
|
19
|
-
*/
|
|
20
|
-
function legacyOptionsAdapter(legacyContext, legacyOptions) {
|
|
21
|
-
let options = {};
|
|
22
|
-
let logger;
|
|
23
|
-
// https://github.com/chimurai/http-proxy-middleware/pull/716
|
|
24
|
-
if (typeof legacyContext === 'string' && !!url.parse(legacyContext).host) {
|
|
25
|
-
throw new Error(`Shorthand syntax is removed from legacyCreateProxyMiddleware().
|
|
26
|
-
Please use "legacyCreateProxyMiddleware({ target: 'http://www.example.org' })" instead.
|
|
27
|
-
|
|
28
|
-
More details: https://github.com/chimurai/http-proxy-middleware/blob/master/MIGRATION.md#removed-shorthand-usage
|
|
29
|
-
`);
|
|
30
|
-
}
|
|
31
|
-
// detect old "context" argument and convert to "options.pathFilter"
|
|
32
|
-
// https://github.com/chimurai/http-proxy-middleware/pull/722/files#diff-a2a171449d862fe29692ce031981047d7ab755ae7f84c707aef80701b3ea0c80L4
|
|
33
|
-
if (legacyContext && legacyOptions) {
|
|
34
|
-
debug('map legacy context/filter to options.pathFilter');
|
|
35
|
-
options = { ...legacyOptions, pathFilter: legacyContext };
|
|
36
|
-
logger = getLegacyLogger(options);
|
|
37
|
-
logger.warn(`[http-proxy-middleware] Legacy "context" argument is deprecated. Migrate your "context" to "options.pathFilter":
|
|
38
|
-
|
|
39
|
-
const options = {
|
|
40
|
-
pathFilter: '${legacyContext}',
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
More details: https://github.com/chimurai/http-proxy-middleware/blob/master/MIGRATION.md#removed-context-argument
|
|
44
|
-
`);
|
|
45
|
-
}
|
|
46
|
-
else if (legacyContext && !legacyOptions) {
|
|
47
|
-
options = { ...legacyContext };
|
|
48
|
-
logger = getLegacyLogger(options);
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
logger = getLegacyLogger({});
|
|
52
|
-
}
|
|
53
|
-
// map old event names to new event names
|
|
54
|
-
// https://github.com/chimurai/http-proxy-middleware/pull/745/files#diff-c54113cf61ec99691748a3890bfbeb00e10efb3f0a76f03a0fd9ec49072e410aL48-L53
|
|
55
|
-
Object.entries(proxyEventMap).forEach(([legacyEventName, proxyEventName]) => {
|
|
56
|
-
if (options[legacyEventName]) {
|
|
57
|
-
options.on = { ...options.on };
|
|
58
|
-
options.on[proxyEventName] = options[legacyEventName];
|
|
59
|
-
debug('map legacy event "%s" to "on.%s"', legacyEventName, proxyEventName);
|
|
60
|
-
logger.warn(`[http-proxy-middleware] Legacy "${legacyEventName}" is deprecated. Migrate to "options.on.${proxyEventName}":
|
|
61
|
-
|
|
62
|
-
const options = {
|
|
63
|
-
on: {
|
|
64
|
-
${proxyEventName}: () => {},
|
|
65
|
-
},
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
More details: https://github.com/chimurai/http-proxy-middleware/blob/master/MIGRATION.md#refactored-proxy-events
|
|
69
|
-
`);
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
// map old logProvider to new logger
|
|
73
|
-
// https://github.com/chimurai/http-proxy-middleware/pull/749
|
|
74
|
-
const logProvider = options.logProvider && options.logProvider();
|
|
75
|
-
const logLevel = options.logLevel;
|
|
76
|
-
debug('legacy logLevel', logLevel);
|
|
77
|
-
debug('legacy logProvider: %O', logProvider);
|
|
78
|
-
if (typeof logLevel === 'string' && logLevel !== 'silent') {
|
|
79
|
-
debug('map "logProvider" to "logger"');
|
|
80
|
-
logger.warn(`[http-proxy-middleware] Legacy "logLevel" and "logProvider" are deprecated. Migrate to "options.logger":
|
|
81
|
-
|
|
82
|
-
const options = {
|
|
83
|
-
logger: console,
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
More details: https://github.com/chimurai/http-proxy-middleware/blob/master/MIGRATION.md#removed-logprovider-and-loglevel-options
|
|
87
|
-
`);
|
|
88
|
-
}
|
|
89
|
-
return options;
|
|
90
|
-
}
|
|
91
|
-
function getLegacyLogger(options) {
|
|
92
|
-
const legacyLogger = options.logProvider && options.logProvider();
|
|
93
|
-
if (legacyLogger) {
|
|
94
|
-
options.logger = legacyLogger;
|
|
95
|
-
}
|
|
96
|
-
return (0, logger_1.getLogger)(options);
|
|
97
|
-
}
|
package/dist/legacy/public.d.ts
DELETED
package/dist/legacy/public.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.legacyCreateProxyMiddleware = void 0;
|
|
4
|
-
var create_proxy_middleware_1 = require("./create-proxy-middleware");
|
|
5
|
-
Object.defineProperty(exports, "legacyCreateProxyMiddleware", { enumerable: true, get: function () { return create_proxy_middleware_1.legacyCreateProxyMiddleware; } });
|
package/dist/legacy/types.d.ts
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import type * as http from 'http';
|
|
2
|
-
import { Options } from '../types';
|
|
3
|
-
/**
|
|
4
|
-
* @deprecated
|
|
5
|
-
*
|
|
6
|
-
* Will be removed in a future version.
|
|
7
|
-
*/
|
|
8
|
-
export interface LegacyOptions<TReq = http.IncomingMessage, TRes = http.ServerResponse> extends Options<TReq, TRes> {
|
|
9
|
-
/**
|
|
10
|
-
* @deprecated
|
|
11
|
-
* Use `on.error` instead.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```js
|
|
15
|
-
* {
|
|
16
|
-
* on: {
|
|
17
|
-
* error: () => {}
|
|
18
|
-
* }
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
onError?: (...args: any[]) => void;
|
|
22
|
-
/**
|
|
23
|
-
* @deprecated
|
|
24
|
-
* Use `on.proxyRes` instead.
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```js
|
|
28
|
-
* {
|
|
29
|
-
* on: {
|
|
30
|
-
* proxyRes: () => {}
|
|
31
|
-
* }
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
onProxyRes?: (...args: any[]) => void;
|
|
35
|
-
/**
|
|
36
|
-
* @deprecated
|
|
37
|
-
* Use `on.proxyReq` instead.
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```js
|
|
41
|
-
* {
|
|
42
|
-
* on: {
|
|
43
|
-
* proxyReq: () => {}
|
|
44
|
-
* }
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
onProxyReq?: (...args: any[]) => void;
|
|
48
|
-
/**
|
|
49
|
-
* @deprecated
|
|
50
|
-
* Use `on.proxyReqWs` instead.
|
|
51
|
-
*
|
|
52
|
-
* @example
|
|
53
|
-
* ```js
|
|
54
|
-
* {
|
|
55
|
-
* on: {
|
|
56
|
-
* proxyReqWs: () => {}
|
|
57
|
-
* }
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
onProxyReqWs?: (...args: any[]) => void;
|
|
61
|
-
/**
|
|
62
|
-
* @deprecated
|
|
63
|
-
* Use `on.open` instead.
|
|
64
|
-
*
|
|
65
|
-
* @example
|
|
66
|
-
* ```js
|
|
67
|
-
* {
|
|
68
|
-
* on: {
|
|
69
|
-
* open: () => {}
|
|
70
|
-
* }
|
|
71
|
-
* ```
|
|
72
|
-
*/
|
|
73
|
-
onOpen?: (...args: any[]) => void;
|
|
74
|
-
/**
|
|
75
|
-
* @deprecated
|
|
76
|
-
* Use `on.close` instead.
|
|
77
|
-
*
|
|
78
|
-
* @example
|
|
79
|
-
* ```js
|
|
80
|
-
* {
|
|
81
|
-
* on: {
|
|
82
|
-
* close: () => {}
|
|
83
|
-
* }
|
|
84
|
-
* ```
|
|
85
|
-
*/
|
|
86
|
-
onClose?: (...args: any[]) => void;
|
|
87
|
-
/**
|
|
88
|
-
* @deprecated
|
|
89
|
-
* Use `logger` instead.
|
|
90
|
-
*
|
|
91
|
-
* @example
|
|
92
|
-
* ```js
|
|
93
|
-
* {
|
|
94
|
-
* logger: console
|
|
95
|
-
* }
|
|
96
|
-
* ```
|
|
97
|
-
*/
|
|
98
|
-
logProvider?: any;
|
|
99
|
-
/**
|
|
100
|
-
* @deprecated
|
|
101
|
-
* Use `logger` instead.
|
|
102
|
-
*
|
|
103
|
-
* @example
|
|
104
|
-
* ```js
|
|
105
|
-
* {
|
|
106
|
-
* logger: console
|
|
107
|
-
* }
|
|
108
|
-
* ```
|
|
109
|
-
*/
|
|
110
|
-
logLevel?: any;
|
|
111
|
-
}
|
package/dist/legacy/types.js
DELETED