http-proxy-middleware 1.2.1 → 2.0.1
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 +22 -2
- package/dist/handlers/fix-request-body.d.ts +6 -0
- package/dist/handlers/fix-request-body.js +26 -0
- package/dist/handlers/public.d.ts +1 -0
- package/dist/handlers/public.js +3 -1
- package/dist/handlers/response-interceptor.js +19 -30
- package/dist/http-proxy-middleware.js +16 -25
- package/dist/router.js +10 -21
- package/dist/types.d.ts +27 -11
- package/dist/types.js +4 -1
- package/package.json +27 -29
- package/CHANGELOG.md +0 -209
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# http-proxy-middleware
|
|
2
2
|
|
|
3
|
-
[](https://img.shields.io/github/workflow/status/chimurai/http-proxy-middleware/CI/master?style=flat-square)](https://github.com/chimurai/http-proxy-middleware/actions?query=branch%3Amaster)
|
|
4
4
|
[](https://coveralls.io/r/chimurai/http-proxy-middleware)
|
|
5
5
|
[](https://david-dm.org/chimurai/http-proxy-middleware#info=dependencies)
|
|
6
6
|
[](https://snyk.io/test/npm/http-proxy-middleware)
|
|
@@ -69,6 +69,7 @@ _All_ `http-proxy` [options](https://github.com/nodejitsu/node-http-proxy#option
|
|
|
69
69
|
- [app.use\(path, proxy\)](#appusepath-proxy)
|
|
70
70
|
- [WebSocket](#websocket)
|
|
71
71
|
- [External WebSocket upgrade](#external-websocket-upgrade)
|
|
72
|
+
- [Intercept and manipulate requests](#intercept-and-manipulate-requests)
|
|
72
73
|
- [Intercept and manipulate responses](#intercept-and-manipulate-responses)
|
|
73
74
|
- [Working examples](#working-examples)
|
|
74
75
|
- [Recipes](#recipes)
|
|
@@ -482,6 +483,25 @@ const server = app.listen(3000);
|
|
|
482
483
|
server.on('upgrade', wsProxy.upgrade); // <-- subscribe to http 'upgrade'
|
|
483
484
|
```
|
|
484
485
|
|
|
486
|
+
## Intercept and manipulate requests
|
|
487
|
+
|
|
488
|
+
Intercept requests from downstream by defining `onProxyReq` in `createProxyMiddleware`.
|
|
489
|
+
|
|
490
|
+
Currently the only pre-provided request interceptor is `fixRequestBody`, which is used to fix proxied POST requests when `bodyParser` is applied before this middleware.
|
|
491
|
+
|
|
492
|
+
Example:
|
|
493
|
+
|
|
494
|
+
```javascript
|
|
495
|
+
const { createProxyMiddleware, fixRequestBody } = require('http-proxy-middleware');
|
|
496
|
+
|
|
497
|
+
const proxy = createProxyMiddleware({
|
|
498
|
+
/**
|
|
499
|
+
* Fix bodyParser
|
|
500
|
+
**/
|
|
501
|
+
onProxyReq: fixRequestBody,
|
|
502
|
+
});
|
|
503
|
+
```
|
|
504
|
+
|
|
485
505
|
## Intercept and manipulate responses
|
|
486
506
|
|
|
487
507
|
Intercept responses from upstream with `responseInterceptor`. (Make sure to set `selfHandleResponse: true`)
|
|
@@ -507,7 +527,7 @@ const proxy = createProxyMiddleware({
|
|
|
507
527
|
* Intercept response and replace 'Hello' with 'Goodbye'
|
|
508
528
|
**/
|
|
509
529
|
onProxyRes: responseInterceptor(async (responseBuffer, proxyRes, req, res) => {
|
|
510
|
-
const response = responseBuffer.toString('
|
|
530
|
+
const response = responseBuffer.toString('utf8'); // convert buffer to string
|
|
511
531
|
return response.replace('Hello', 'Goodbye'); // manipulate response and return the result
|
|
512
532
|
}),
|
|
513
533
|
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fixRequestBody = void 0;
|
|
4
|
+
const querystring = require("querystring");
|
|
5
|
+
/**
|
|
6
|
+
* Fix proxied body if bodyParser is involved.
|
|
7
|
+
*/
|
|
8
|
+
function fixRequestBody(proxyReq, req) {
|
|
9
|
+
const requestBody = req.body;
|
|
10
|
+
if (!requestBody || !Object.keys(requestBody).length) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const contentType = proxyReq.getHeader('Content-Type');
|
|
14
|
+
const writeBody = (bodyData) => {
|
|
15
|
+
// deepcode ignore ContentLengthInCode: bodyParser fix
|
|
16
|
+
proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData));
|
|
17
|
+
proxyReq.write(bodyData);
|
|
18
|
+
};
|
|
19
|
+
if (contentType && contentType.includes('application/json')) {
|
|
20
|
+
writeBody(JSON.stringify(requestBody));
|
|
21
|
+
}
|
|
22
|
+
if (contentType === 'application/x-www-form-urlencoded') {
|
|
23
|
+
writeBody(querystring.stringify(requestBody));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.fixRequestBody = fixRequestBody;
|
package/dist/handlers/public.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.responseInterceptor = void 0;
|
|
3
|
+
exports.fixRequestBody = exports.responseInterceptor = void 0;
|
|
4
4
|
var response_interceptor_1 = require("./response-interceptor");
|
|
5
5
|
Object.defineProperty(exports, "responseInterceptor", { enumerable: true, get: function () { return response_interceptor_1.responseInterceptor; } });
|
|
6
|
+
var fix_request_body_1 = require("./fix-request-body");
|
|
7
|
+
Object.defineProperty(exports, "fixRequestBody", { enumerable: true, get: function () { return fix_request_body_1.fixRequestBody; } });
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.responseInterceptor = void 0;
|
|
13
4
|
const zlib = require("zlib");
|
|
@@ -19,27 +10,25 @@ const zlib = require("zlib");
|
|
|
19
10
|
* NOTE: must set options.selfHandleResponse=true (prevent automatic call of res.end())
|
|
20
11
|
*/
|
|
21
12
|
function responseInterceptor(interceptor) {
|
|
22
|
-
return function proxyRes(proxyRes, req, res) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
res.end(`Error fetching proxied request: ${error.message}`);
|
|
42
|
-
});
|
|
13
|
+
return async function proxyRes(proxyRes, req, res) {
|
|
14
|
+
const originalProxyRes = proxyRes;
|
|
15
|
+
let buffer = Buffer.from('', 'utf8');
|
|
16
|
+
// decompress proxy response
|
|
17
|
+
const _proxyRes = decompress(proxyRes, proxyRes.headers['content-encoding']);
|
|
18
|
+
// concat data stream
|
|
19
|
+
_proxyRes.on('data', (chunk) => (buffer = Buffer.concat([buffer, chunk])));
|
|
20
|
+
_proxyRes.on('end', async () => {
|
|
21
|
+
// copy original headers
|
|
22
|
+
copyHeaders(proxyRes, res);
|
|
23
|
+
// call interceptor with intercepted response (buffer)
|
|
24
|
+
const interceptedBuffer = Buffer.from(await interceptor(buffer, originalProxyRes, req, res));
|
|
25
|
+
// set correct content-length (with double byte character support)
|
|
26
|
+
res.setHeader('content-length', Buffer.byteLength(interceptedBuffer, 'utf8'));
|
|
27
|
+
res.write(interceptedBuffer);
|
|
28
|
+
res.end();
|
|
29
|
+
});
|
|
30
|
+
_proxyRes.on('error', (error) => {
|
|
31
|
+
res.end(`Error fetching proxied request: ${error.message}`);
|
|
43
32
|
});
|
|
44
33
|
};
|
|
45
34
|
}
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.HttpProxyMiddleware = void 0;
|
|
13
4
|
const httpProxy = require("http-proxy");
|
|
@@ -23,11 +14,11 @@ class HttpProxyMiddleware {
|
|
|
23
14
|
this.wsInternalSubscribed = false;
|
|
24
15
|
this.serverOnCloseSubscribed = false;
|
|
25
16
|
// https://github.com/Microsoft/TypeScript/wiki/'this'-in-TypeScript#red-flags-for-this
|
|
26
|
-
this.middleware = (req, res, next) =>
|
|
17
|
+
this.middleware = async (req, res, next) => {
|
|
27
18
|
var _a, _b;
|
|
28
19
|
if (this.shouldProxy(this.config.context, req)) {
|
|
29
20
|
try {
|
|
30
|
-
const activeProxyOptions =
|
|
21
|
+
const activeProxyOptions = await this.prepareProxyRequest(req);
|
|
31
22
|
this.proxy.web(req, res, activeProxyOptions);
|
|
32
23
|
}
|
|
33
24
|
catch (err) {
|
|
@@ -57,7 +48,7 @@ class HttpProxyMiddleware {
|
|
|
57
48
|
// use initial request to access the server object to subscribe to http upgrade event
|
|
58
49
|
this.catchUpgradeRequest(server);
|
|
59
50
|
}
|
|
60
|
-
}
|
|
51
|
+
};
|
|
61
52
|
this.catchUpgradeRequest = (server) => {
|
|
62
53
|
if (!this.wsInternalSubscribed) {
|
|
63
54
|
server.on('upgrade', this.handleUpgrade);
|
|
@@ -66,13 +57,13 @@ class HttpProxyMiddleware {
|
|
|
66
57
|
this.wsInternalSubscribed = true;
|
|
67
58
|
}
|
|
68
59
|
};
|
|
69
|
-
this.handleUpgrade = (req, socket, head) =>
|
|
60
|
+
this.handleUpgrade = async (req, socket, head) => {
|
|
70
61
|
if (this.shouldProxy(this.config.context, req)) {
|
|
71
|
-
const activeProxyOptions =
|
|
62
|
+
const activeProxyOptions = await this.prepareProxyRequest(req);
|
|
72
63
|
this.proxy.ws(req, socket, head, activeProxyOptions);
|
|
73
64
|
this.logger.info('[HPM] Upgrading to WebSocket');
|
|
74
65
|
}
|
|
75
|
-
}
|
|
66
|
+
};
|
|
76
67
|
/**
|
|
77
68
|
* Determine whether request should be proxied.
|
|
78
69
|
*
|
|
@@ -93,7 +84,7 @@ class HttpProxyMiddleware {
|
|
|
93
84
|
* @param {Object} req
|
|
94
85
|
* @return {Object} proxy options
|
|
95
86
|
*/
|
|
96
|
-
this.prepareProxyRequest = (req) =>
|
|
87
|
+
this.prepareProxyRequest = async (req) => {
|
|
97
88
|
// https://github.com/chimurai/http-proxy-middleware/issues/17
|
|
98
89
|
// https://github.com/chimurai/http-proxy-middleware/issues/94
|
|
99
90
|
req.url = req.originalUrl || req.url;
|
|
@@ -103,30 +94,30 @@ class HttpProxyMiddleware {
|
|
|
103
94
|
// Apply in order:
|
|
104
95
|
// 1. option.router
|
|
105
96
|
// 2. option.pathRewrite
|
|
106
|
-
|
|
107
|
-
|
|
97
|
+
await this.applyRouter(req, newProxyOptions);
|
|
98
|
+
await this.applyPathRewrite(req, this.pathRewriter);
|
|
108
99
|
// debug logging for both http(s) and websockets
|
|
109
100
|
if (this.proxyOptions.logLevel === 'debug') {
|
|
110
101
|
const arrow = logger_1.getArrow(originalPath, req.url, this.proxyOptions.target, newProxyOptions.target);
|
|
111
102
|
this.logger.debug('[HPM] %s %s %s %s', req.method, originalPath, arrow, newProxyOptions.target);
|
|
112
103
|
}
|
|
113
104
|
return newProxyOptions;
|
|
114
|
-
}
|
|
105
|
+
};
|
|
115
106
|
// Modify option.target when router present.
|
|
116
|
-
this.applyRouter = (req, options) =>
|
|
107
|
+
this.applyRouter = async (req, options) => {
|
|
117
108
|
let newTarget;
|
|
118
109
|
if (options.router) {
|
|
119
|
-
newTarget =
|
|
110
|
+
newTarget = await Router.getTarget(req, options);
|
|
120
111
|
if (newTarget) {
|
|
121
112
|
this.logger.debug('[HPM] Router new target: %s -> "%s"', options.target, newTarget);
|
|
122
113
|
options.target = newTarget;
|
|
123
114
|
}
|
|
124
115
|
}
|
|
125
|
-
}
|
|
116
|
+
};
|
|
126
117
|
// rewrite path
|
|
127
|
-
this.applyPathRewrite = (req, pathRewriter) =>
|
|
118
|
+
this.applyPathRewrite = async (req, pathRewriter) => {
|
|
128
119
|
if (pathRewriter) {
|
|
129
|
-
const path =
|
|
120
|
+
const path = await pathRewriter(req.url, req);
|
|
130
121
|
if (typeof path === 'string') {
|
|
131
122
|
req.url = path;
|
|
132
123
|
}
|
|
@@ -134,7 +125,7 @@ class HttpProxyMiddleware {
|
|
|
134
125
|
this.logger.info('[HPM] pathRewrite: No rewritten path found. (%s)', req.url);
|
|
135
126
|
}
|
|
136
127
|
}
|
|
137
|
-
}
|
|
128
|
+
};
|
|
138
129
|
this.logError = (err, req, res, target) => {
|
|
139
130
|
var _a;
|
|
140
131
|
const hostname = ((_a = req.headers) === null || _a === void 0 ? void 0 : _a.host) || req.hostname || req.host; // (websocket) || (node0.10 || node 4/5)
|
package/dist/router.js
CHANGED
|
@@ -1,30 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.getTarget = void 0;
|
|
13
4
|
const isPlainObj = require("is-plain-obj");
|
|
14
5
|
const logger_1 = require("./logger");
|
|
15
6
|
const logger = logger_1.getInstance();
|
|
16
|
-
function getTarget(req, config) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return newTarget;
|
|
27
|
-
});
|
|
7
|
+
async function getTarget(req, config) {
|
|
8
|
+
let newTarget;
|
|
9
|
+
const router = config.router;
|
|
10
|
+
if (isPlainObj(router)) {
|
|
11
|
+
newTarget = getTargetFromProxyTable(req, router);
|
|
12
|
+
}
|
|
13
|
+
else if (typeof router === 'function') {
|
|
14
|
+
newTarget = await router(req);
|
|
15
|
+
}
|
|
16
|
+
return newTarget;
|
|
28
17
|
}
|
|
29
18
|
exports.getTarget = getTarget;
|
|
30
19
|
function getTargetFromProxyTable(req, table) {
|
package/dist/types.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Based on definition by DefinitelyTyped:
|
|
3
|
+
* https://github.com/DefinitelyTyped/DefinitelyTyped/blob/6f529c6c67a447190f86bfbf894d1061e41e07b7/types/http-proxy-middleware/index.d.ts
|
|
4
|
+
*/
|
|
1
5
|
/// <reference types="node" />
|
|
2
|
-
import * as express from 'express';
|
|
3
|
-
import * as http from 'http';
|
|
4
|
-
import * as httpProxy from 'http-proxy';
|
|
5
|
-
import * as net from 'net';
|
|
6
|
+
import type * as express from 'express';
|
|
7
|
+
import type * as http from 'http';
|
|
8
|
+
import type * as httpProxy from 'http-proxy';
|
|
9
|
+
import type * as net from 'net';
|
|
10
|
+
import type * as url from 'url';
|
|
6
11
|
export interface Request extends express.Request {
|
|
7
12
|
}
|
|
8
13
|
export interface Response extends express.Response {
|
|
@@ -19,13 +24,13 @@ export interface Options extends httpProxy.ServerOptions {
|
|
|
19
24
|
[hostOrPath: string]: httpProxy.ServerOptions['target'];
|
|
20
25
|
} | ((req: Request) => httpProxy.ServerOptions['target']) | ((req: Request) => Promise<httpProxy.ServerOptions['target']>);
|
|
21
26
|
logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'silent';
|
|
22
|
-
logProvider
|
|
23
|
-
onError
|
|
24
|
-
onProxyRes
|
|
25
|
-
onProxyReq
|
|
26
|
-
onProxyReqWs
|
|
27
|
-
onOpen
|
|
28
|
-
onClose
|
|
27
|
+
logProvider?: LogProviderCallback;
|
|
28
|
+
onError?: OnErrorCallback;
|
|
29
|
+
onProxyRes?: OnProxyResCallback;
|
|
30
|
+
onProxyReq?: OnProxyReqCallback;
|
|
31
|
+
onProxyReqWs?: OnProxyReqWsCallback;
|
|
32
|
+
onOpen?: OnOpenCallback;
|
|
33
|
+
onClose?: OnCloseCallback;
|
|
29
34
|
}
|
|
30
35
|
interface LogProvider {
|
|
31
36
|
log: Logger;
|
|
@@ -35,4 +40,15 @@ interface LogProvider {
|
|
|
35
40
|
error?: Logger;
|
|
36
41
|
}
|
|
37
42
|
declare type Logger = (...args: any[]) => void;
|
|
43
|
+
export declare type LogProviderCallback = (provider: LogProvider) => LogProvider;
|
|
44
|
+
/**
|
|
45
|
+
* Use types based on the events listeners from http-proxy
|
|
46
|
+
* https://github.com/DefinitelyTyped/DefinitelyTyped/blob/51504fd999031b7f025220fab279f1b2155cbaff/types/http-proxy/index.d.ts
|
|
47
|
+
*/
|
|
48
|
+
export declare type OnErrorCallback = (err: Error, req: http.IncomingMessage, res: http.ServerResponse, target?: string | Partial<url.Url>) => void;
|
|
49
|
+
export declare type OnProxyResCallback = (proxyRes: http.IncomingMessage, req: http.IncomingMessage, res: http.ServerResponse) => void;
|
|
50
|
+
export declare type OnProxyReqCallback = (proxyReq: http.ClientRequest, req: http.IncomingMessage, res: http.ServerResponse, options: httpProxy.ServerOptions) => void;
|
|
51
|
+
export declare type OnProxyReqWsCallback = (proxyReq: http.ClientRequest, req: http.IncomingMessage, socket: net.Socket, options: httpProxy.ServerOptions, head: any) => void;
|
|
52
|
+
export declare type OnCloseCallback = (proxyRes: http.IncomingMessage, proxySocket: net.Socket, proxyHead: any) => void;
|
|
53
|
+
export declare type OnOpenCallback = (proxySocket: net.Socket) => void;
|
|
38
54
|
export {};
|
package/dist/types.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Based on definition by DefinitelyTyped:
|
|
4
|
+
* https://github.com/DefinitelyTyped/DefinitelyTyped/blob/6f529c6c67a447190f86bfbf894d1061e41e07b7/types/http-proxy-middleware/index.d.ts
|
|
5
|
+
*/
|
|
3
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "http-proxy-middleware",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "The one-liner node.js proxy middleware for connect, express and browser-sync",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -15,11 +15,13 @@
|
|
|
15
15
|
"eslint:fix": "yarn eslint --fix",
|
|
16
16
|
"prettier": "prettier --list-different \"**/*.{js,ts,md,yml,json,html}\"",
|
|
17
17
|
"prettier:fix": "prettier --write \"**/*.{js,ts,md,yml,json,html}\"",
|
|
18
|
+
"prebuild": "yarn clean",
|
|
18
19
|
"build": "tsc",
|
|
19
20
|
"pretest": "yarn build",
|
|
20
21
|
"test": "jest",
|
|
22
|
+
"precoverage": "yarn build",
|
|
21
23
|
"coverage": "jest --coverage --coverageReporters=lcov",
|
|
22
|
-
"prepare": "
|
|
24
|
+
"prepare": "husky install && yarn build && rm dist/tsconfig.tsbuildinfo"
|
|
23
25
|
},
|
|
24
26
|
"repository": {
|
|
25
27
|
"type": "git",
|
|
@@ -49,33 +51,35 @@
|
|
|
49
51
|
},
|
|
50
52
|
"homepage": "https://github.com/chimurai/http-proxy-middleware#readme",
|
|
51
53
|
"devDependencies": {
|
|
52
|
-
"@commitlint/cli": "^12.
|
|
53
|
-
"@commitlint/config-conventional": "^12.
|
|
54
|
+
"@commitlint/cli": "^12.1.4",
|
|
55
|
+
"@commitlint/config-conventional": "^12.1.4",
|
|
54
56
|
"@types/express": "4.17.7",
|
|
55
57
|
"@types/is-glob": "^4.0.1",
|
|
56
|
-
"@types/jest": "^26.0.
|
|
58
|
+
"@types/jest": "^26.0.23",
|
|
57
59
|
"@types/micromatch": "^4.0.1",
|
|
58
|
-
"@types/node": "^
|
|
59
|
-
"@types/supertest": "^2.0.
|
|
60
|
-
"@types/ws": "^7.4.
|
|
61
|
-
"@typescript-eslint/eslint-plugin": "^4.
|
|
62
|
-
"@typescript-eslint/parser": "^4.
|
|
60
|
+
"@types/node": "^15.6.2",
|
|
61
|
+
"@types/supertest": "^2.0.11",
|
|
62
|
+
"@types/ws": "^7.4.4",
|
|
63
|
+
"@typescript-eslint/eslint-plugin": "^4.26.0",
|
|
64
|
+
"@typescript-eslint/parser": "^4.26.0",
|
|
65
|
+
"body-parser": "^1.19.0",
|
|
63
66
|
"browser-sync": "^2.26.14",
|
|
64
67
|
"connect": "^3.7.0",
|
|
65
|
-
"eslint": "^7.
|
|
66
|
-
"eslint-config-prettier": "^8.
|
|
67
|
-
"eslint-plugin-prettier": "^3.
|
|
68
|
+
"eslint": "^7.27.0",
|
|
69
|
+
"eslint-config-prettier": "^8.3.0",
|
|
70
|
+
"eslint-plugin-prettier": "^3.4.0",
|
|
68
71
|
"express": "^4.17.1",
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"
|
|
72
|
+
"get-port": "^5.1.1",
|
|
73
|
+
"husky": "^6.0.0",
|
|
74
|
+
"jest": "^27.0.3",
|
|
75
|
+
"lint-staged": "^11.0.0",
|
|
76
|
+
"mockttp": "^1.2.2",
|
|
77
|
+
"open": "^8.2.0",
|
|
78
|
+
"prettier": "^2.3.0",
|
|
75
79
|
"supertest": "^6.1.3",
|
|
76
|
-
"ts-jest": "^
|
|
77
|
-
"typescript": "^4.2
|
|
78
|
-
"ws": "^7.4.
|
|
80
|
+
"ts-jest": "^27.0.2",
|
|
81
|
+
"typescript": "^4.3.2",
|
|
82
|
+
"ws": "^7.4.6"
|
|
79
83
|
},
|
|
80
84
|
"dependencies": {
|
|
81
85
|
"@types/http-proxy": "^1.17.5",
|
|
@@ -85,13 +89,7 @@
|
|
|
85
89
|
"micromatch": "^4.0.2"
|
|
86
90
|
},
|
|
87
91
|
"engines": {
|
|
88
|
-
"node": ">=
|
|
89
|
-
},
|
|
90
|
-
"husky": {
|
|
91
|
-
"hooks": {
|
|
92
|
-
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
|
|
93
|
-
"pre-commit": "lint-staged"
|
|
94
|
-
}
|
|
92
|
+
"node": ">=12.0.0"
|
|
95
93
|
},
|
|
96
94
|
"commitlint": {
|
|
97
95
|
"extends": [
|
package/CHANGELOG.md
DELETED
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
## [v1.2.1](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.2.1)
|
|
4
|
-
|
|
5
|
-
- fix(response interceptor): proxy original response headers ([#563](https://github.com/chimurai/http-proxy-middleware/pull/563))
|
|
6
|
-
|
|
7
|
-
## [v1.2.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.2.0)
|
|
8
|
-
|
|
9
|
-
- feat(handler): response interceptor ([#520](https://github.com/chimurai/http-proxy-middleware/pull/520))
|
|
10
|
-
- fix(log error): handle undefined target when websocket errors ([#527](https://github.com/chimurai/http-proxy-middleware/pull/527))
|
|
11
|
-
|
|
12
|
-
## [v1.1.2](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.1.2)
|
|
13
|
-
|
|
14
|
-
- fix(log error): handle optional target ([#523](https://github.com/chimurai/http-proxy-middleware/pull/523))
|
|
15
|
-
|
|
16
|
-
## [v1.1.1](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.1.1)
|
|
17
|
-
|
|
18
|
-
- fix(error handler): re-throw http-proxy missing target error ([#517](https://github.com/chimurai/http-proxy-middleware/pull/517))
|
|
19
|
-
- refactor(dependency): remove `camelcase`
|
|
20
|
-
- fix(option): optional `target` when `router` is used ([#512](https://github.com/chimurai/http-proxy-middleware/pull/512))
|
|
21
|
-
|
|
22
|
-
## [v1.1.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.1.0)
|
|
23
|
-
|
|
24
|
-
- fix(errorHandler): fix confusing error message ([#509](https://github.com/chimurai/http-proxy-middleware/pull/509))
|
|
25
|
-
- fix(proxy): close proxy when server closes ([#508](https://github.com/chimurai/http-proxy-middleware/pull/508))
|
|
26
|
-
- refactor(lodash): remove lodash ([#459](https://github.com/chimurai/http-proxy-middleware/pull/459)) ([#507](https://github.com/chimurai/http-proxy-middleware/pull/507)) ([TrySound](https://github.com/TrySound))
|
|
27
|
-
- fix(ETIMEDOUT): return 504 on ETIMEDOUT ([#480](https://github.com/chimurai/http-proxy-middleware/pull/480)) ([aremishevsky](https://github.com/aremishevsky))
|
|
28
|
-
|
|
29
|
-
## [v1.0.6](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.0.6)
|
|
30
|
-
|
|
31
|
-
- chore(deps): lodash 4.17.20 ([#475](https://github.com/chimurai/http-proxy-middleware/pull/475))
|
|
32
|
-
|
|
33
|
-
## [v1.0.5](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.0.6)
|
|
34
|
-
|
|
35
|
-
- chore(deps): lodash 4.17.19 ([#454](https://github.com/chimurai/http-proxy-middleware/pull/454))
|
|
36
|
-
|
|
37
|
-
## [v1.0.4](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.0.4)
|
|
38
|
-
|
|
39
|
-
- chore(deps): http-proxy 1.18.1 ([#442](https://github.com/chimurai/http-proxy-middleware/pull/442))
|
|
40
|
-
|
|
41
|
-
## [v1.0.3](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.0.3)
|
|
42
|
-
|
|
43
|
-
- build(package): exclude build artifact tsconfig.tsbuildinfo ([#415](https://github.com/chimurai/http-proxy-middleware/pull/415))
|
|
44
|
-
|
|
45
|
-
## [v1.0.2](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.0.2)
|
|
46
|
-
|
|
47
|
-
- fix(router): handle rejected promise in custom router ([#410](https://github.com/chimurai/http-proxy-middleware/pull/413)) ([bforbis](https://github.com/bforbis))
|
|
48
|
-
|
|
49
|
-
## [v1.0.1](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.0.1)
|
|
50
|
-
|
|
51
|
-
- fix(typescript): fix proxyRes and router types ([#410](https://github.com/chimurai/http-proxy-middleware/issues/410)) ([dylang](https://github.com/dylang))
|
|
52
|
-
|
|
53
|
-
## [v1.0.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.0.0)
|
|
54
|
-
|
|
55
|
-
- feat(createProxyMiddleware): explicit import http-proxy-middleware ([BREAKING CHANGE](https://github.com/chimurai/http-proxy-middleware/releases))([#400](https://github.com/chimurai/http-proxy-middleware/issues/400#issuecomment-587162378))
|
|
56
|
-
- feat(typescript): export http-proxy-middleware types ([#400](https://github.com/chimurai/http-proxy-middleware/issues/400))
|
|
57
|
-
- fix(typescript): ES6 target - TS1192 ([#400](https://github.com/chimurai/http-proxy-middleware/issues/400#issuecomment-587064349))
|
|
58
|
-
|
|
59
|
-
## [v0.21.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.21.0)
|
|
60
|
-
|
|
61
|
-
- feat(http-proxy): bump to v1.18.0
|
|
62
|
-
- feat: async router ([#379](https://github.com/chimurai/http-proxy-middleware/issues/379)) ([LiranBri](https://github.com/LiranBri))
|
|
63
|
-
- feat(typescript): types support ([#369](https://github.com/chimurai/http-proxy-middleware/pull/369))
|
|
64
|
-
- feat: async pathRewrite ([#397](https://github.com/chimurai/http-proxy-middleware/pull/397)) ([rsethc](https://github.com/rsethc))
|
|
65
|
-
|
|
66
|
-
## [v0.20.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.20.0)
|
|
67
|
-
|
|
68
|
-
- fix(ws): concurrent websocket requests do not get upgraded ([#335](https://github.com/chimurai/http-proxy-middleware/issues/335))
|
|
69
|
-
- chore: drop node 6 (BREAKING CHANGE)
|
|
70
|
-
- chore: update to micromatch@4 ([BREAKING CHANGE](https://github.com/micromatch/micromatch/blob/master/CHANGELOG.md#400---2019-03-20))
|
|
71
|
-
- chore: update dev dependencies
|
|
72
|
-
- refactor: migrate to typescript ([#328](https://github.com/chimurai/http-proxy-middleware/pull/328))
|
|
73
|
-
- feat(middleware): Promise / async support ([#328](https://github.com/chimurai/http-proxy-middleware/pull/328/files#diff-7890bfeb41abb0fc0ef2670749c84077R50))
|
|
74
|
-
- refactor: remove legacy options `proxyHost` and `proxyTable` (BREAKING CHANGE)
|
|
75
|
-
|
|
76
|
-
## [v0.19.1](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.19.1)
|
|
77
|
-
|
|
78
|
-
- fix(log): handle case when error code is missing ([#303](https://github.com/chimurai/http-proxy-middleware/pull/303))
|
|
79
|
-
|
|
80
|
-
## [v0.19.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.19.0)
|
|
81
|
-
|
|
82
|
-
- feat(http-proxy): bump to v1.17.0 ([#261](https://github.com/chimurai/http-proxy-middleware/pull/261))
|
|
83
|
-
|
|
84
|
-
## [v0.18.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.18.0)
|
|
85
|
-
|
|
86
|
-
- fix(vulnerability): update micromatch to v3.x ([npm:braces:20180219](https://snyk.io/test/npm/http-proxy-middleware?tab=issues&severity=high&severity=medium&severity=low#npm:braces:20180219))
|
|
87
|
-
- test(node): drop node 0.x support ([#212](https://github.com/chimurai/http-proxy-middleware/pull/212))
|
|
88
|
-
|
|
89
|
-
## [v0.17.4](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.17.4)
|
|
90
|
-
|
|
91
|
-
- fix(ntlm authentication): fixed bug preventing proxying with ntlm authentication. ([#132](https://github.com/chimurai/http-proxy-middleware/pull/149)) (Thanks: [EladBezalel](https://github.com/EladBezalel), [oshri551](https://github.com/oshri551))
|
|
92
|
-
|
|
93
|
-
## [v0.17.3](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.17.3)
|
|
94
|
-
|
|
95
|
-
- fix(onError): improve default proxy error handling. http status codes (504, 502 and 500). ([#132](https://github.com/chimurai/http-proxy-middleware/pull/132)) ([graingert](https://github.com/graingert))
|
|
96
|
-
|
|
97
|
-
## [v0.17.2](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.17.2)
|
|
98
|
-
|
|
99
|
-
- feat(logging): improve error message & add link to Node errors page. ([#106](https://github.com/chimurai/http-proxy-middleware/pull/106)) ([cloudmu](https://github.com/cloudmu))
|
|
100
|
-
- feat(pathRewrite): path can be empty string. ([#110](https://github.com/chimurai/http-proxy-middleware/pull/110)) ([sunnylqm](https://github.com/sunnylqm))
|
|
101
|
-
- bug(websocket): memory leak when option 'ws:true' is used. ([#114](https://github.com/chimurai/http-proxy-middleware/pull/114)) ([julbra](https://github.com/julbra))
|
|
102
|
-
- chore(package.json): reduce package size. ([#109](https://github.com/chimurai/http-proxy-middleware/pull/109))
|
|
103
|
-
|
|
104
|
-
## [v0.17.1](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.17.1)
|
|
105
|
-
|
|
106
|
-
- fix(Express sub Router): 404 on non-proxy routes ([#94](https://github.com/chimurai/http-proxy-middleware/issues/94))
|
|
107
|
-
|
|
108
|
-
## [v0.17.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.17.0)
|
|
109
|
-
|
|
110
|
-
- fix(context matching): Use [RFC 3986 path](https://tools.ietf.org/html/rfc3986#section-3.3) in context matching. (excludes query parameters)
|
|
111
|
-
|
|
112
|
-
## [v0.16.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.16.0)
|
|
113
|
-
|
|
114
|
-
- deprecated(proxyTable): renamed `proxyTable` to `router`.
|
|
115
|
-
- feat(router): support for custom `router` function.
|
|
116
|
-
|
|
117
|
-
## [v0.15.2](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.15.2)
|
|
118
|
-
|
|
119
|
-
- fix(websocket): fixes websocket upgrade.
|
|
120
|
-
|
|
121
|
-
## [v0.15.1](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.15.1)
|
|
122
|
-
|
|
123
|
-
- feat(pathRewrite): expose `req` object to pathRewrite function.
|
|
124
|
-
- fix(websocket): fixes websocket upgrade when both config.ws and external .upgrade() are used.
|
|
125
|
-
|
|
126
|
-
## [v0.15.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.15.0)
|
|
127
|
-
|
|
128
|
-
- feat(pathRewrite): support for custom pathRewrite function.
|
|
129
|
-
|
|
130
|
-
## [v0.14.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.14.0)
|
|
131
|
-
|
|
132
|
-
- feat(proxy): support proxy creation without context.
|
|
133
|
-
- fix(connect mounting): use connect's `path` configuration to mount proxy.
|
|
134
|
-
|
|
135
|
-
## [v0.13.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.13.0)
|
|
136
|
-
|
|
137
|
-
- feat(context): custom context matcher; when simple `path` matching is not sufficient.
|
|
138
|
-
|
|
139
|
-
## [v0.12.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.12.0)
|
|
140
|
-
|
|
141
|
-
- add option `onProxyReqWs` (subscribe to http-proxy `proxyReqWs` event)
|
|
142
|
-
- add option `onOpen` (subscribe to http-proxy `open` event)
|
|
143
|
-
- add option `onClose` (subscribe to http-proxy `close` event)
|
|
144
|
-
|
|
145
|
-
## [v0.11.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.11.0)
|
|
146
|
-
|
|
147
|
-
- improved logging
|
|
148
|
-
|
|
149
|
-
## [v0.10.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.10.0)
|
|
150
|
-
|
|
151
|
-
- feat(proxyTable) - added proxyTable support for WebSockets.
|
|
152
|
-
- fixed(proxyTable) - ensure original path (not rewritten path) is being used when `proxyTable` is used in conjunction with `pathRewrite`.
|
|
153
|
-
|
|
154
|
-
## [v0.9.1](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.9.1)
|
|
155
|
-
|
|
156
|
-
- fix server crash when socket error not handled correctly.
|
|
157
|
-
|
|
158
|
-
## [v0.9.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.9.0)
|
|
159
|
-
|
|
160
|
-
- support subscribing to http-proxy `proxyReq` event ([trbngr](https://github.com/trbngr))
|
|
161
|
-
- add `logLevel` and `logProvider` support
|
|
162
|
-
|
|
163
|
-
## [v0.8.2](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.8.2)
|
|
164
|
-
|
|
165
|
-
- fix proxyError handler ([mTazelaar](https://github.com/mTazelaar))
|
|
166
|
-
|
|
167
|
-
## [v0.8.1](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.8.1)
|
|
168
|
-
|
|
169
|
-
- fix pathRewrite when `agent` is configured
|
|
170
|
-
|
|
171
|
-
## [v0.8.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.8.0)
|
|
172
|
-
|
|
173
|
-
- support external websocket upgrade
|
|
174
|
-
- fix websocket shorthand
|
|
175
|
-
|
|
176
|
-
## [v0.7.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.7.0)
|
|
177
|
-
|
|
178
|
-
- support shorthand syntax
|
|
179
|
-
- fix express/connect mounting
|
|
180
|
-
|
|
181
|
-
## [v0.6.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.6.0)
|
|
182
|
-
|
|
183
|
-
- support proxyTable
|
|
184
|
-
|
|
185
|
-
## [v0.5.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.5.0)
|
|
186
|
-
|
|
187
|
-
- support subscribing to http-proxy `error` event
|
|
188
|
-
- support subscribing to http-proxy `proxyRes` event
|
|
189
|
-
|
|
190
|
-
## [v0.4.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.4.0)
|
|
191
|
-
|
|
192
|
-
- support websocket
|
|
193
|
-
|
|
194
|
-
## [v0.3.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.3.0)
|
|
195
|
-
|
|
196
|
-
- support wildcard / glob
|
|
197
|
-
|
|
198
|
-
## [v0.2.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.2.0)
|
|
199
|
-
|
|
200
|
-
- support multiple paths
|
|
201
|
-
|
|
202
|
-
## [v0.1.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.1.0)
|
|
203
|
-
|
|
204
|
-
- support path rewrite
|
|
205
|
-
- deprecate proxyHost option
|
|
206
|
-
|
|
207
|
-
## [v0.0.5](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.0.5)
|
|
208
|
-
|
|
209
|
-
- initial release
|