http-proxy-middleware 1.3.0 → 2.0.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 +7 -4
- package/dist/_handlers.js +2 -2
- package/dist/config-factory.js +1 -1
- package/dist/handlers/fix-request-body.d.ts +2 -3
- package/dist/handlers/fix-request-body.js +5 -4
- package/dist/handlers/response-interceptor.js +19 -30
- package/dist/http-proxy-middleware.js +19 -28
- package/dist/path-rewriter.js +1 -1
- package/dist/router.js +11 -22
- package/dist/types.d.ts +27 -11
- package/dist/types.js +4 -1
- package/package.json +39 -38
- package/CHANGELOG.md +0 -214
package/README.md
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
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
|
-
[](https://david-dm.org/chimurai/http-proxy-middleware#info=dependencies)
|
|
6
5
|
[](https://snyk.io/test/npm/http-proxy-middleware)
|
|
7
6
|
[](https://www.npmjs.com/package/http-proxy-middleware)
|
|
8
7
|
|
|
@@ -128,6 +127,7 @@ const express = require('express');
|
|
|
128
127
|
const { createProxyMiddleware } = require('http-proxy-middleware');
|
|
129
128
|
|
|
130
129
|
// proxy middleware options
|
|
130
|
+
/** @type {import('http-proxy-middleware/dist/types').Options} */
|
|
131
131
|
const options = {
|
|
132
132
|
target: 'http://www.example.org', // target host
|
|
133
133
|
changeOrigin: true, // needed for virtual hosted sites
|
|
@@ -341,7 +341,7 @@ Subscribe to [http-proxy events](https://github.com/nodejitsu/node-http-proxy#li
|
|
|
341
341
|
```javascript
|
|
342
342
|
function onOpen(proxySocket) {
|
|
343
343
|
// listen for messages coming FROM the target here
|
|
344
|
-
proxySocket.on('data',
|
|
344
|
+
proxySocket.on('data', hybridParseAndLogMessage);
|
|
345
345
|
}
|
|
346
346
|
```
|
|
347
347
|
|
|
@@ -586,6 +586,9 @@ $ yarn test
|
|
|
586
586
|
|
|
587
587
|
# code coverage
|
|
588
588
|
$ yarn cover
|
|
589
|
+
|
|
590
|
+
# check spelling mistakes
|
|
591
|
+
$ yarn spellcheck
|
|
589
592
|
```
|
|
590
593
|
|
|
591
594
|
## Changelog
|
|
@@ -596,4 +599,4 @@ $ yarn cover
|
|
|
596
599
|
|
|
597
600
|
The MIT License (MIT)
|
|
598
601
|
|
|
599
|
-
Copyright (c) 2015-
|
|
602
|
+
Copyright (c) 2015-2022 Steven Chim
|
package/dist/_handlers.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getHandlers = exports.init = void 0;
|
|
4
4
|
const logger_1 = require("./logger");
|
|
5
|
-
const logger = logger_1.getInstance();
|
|
5
|
+
const logger = (0, logger_1.getInstance)();
|
|
6
6
|
function init(proxy, option) {
|
|
7
7
|
const handlers = getHandlers(option);
|
|
8
8
|
for (const eventName of Object.keys(handlers)) {
|
|
@@ -66,7 +66,7 @@ function defaultErrorHandler(err, req, res) {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
res.end(`Error
|
|
69
|
+
res.end(`Error occurred while trying to proxy: ${host}${req.url}`);
|
|
70
70
|
}
|
|
71
71
|
function logClose(req, socket, head) {
|
|
72
72
|
// view disconnected websocket connections
|
package/dist/config-factory.js
CHANGED
|
@@ -5,7 +5,7 @@ const isPlainObj = require("is-plain-obj");
|
|
|
5
5
|
const url = require("url");
|
|
6
6
|
const errors_1 = require("./errors");
|
|
7
7
|
const logger_1 = require("./logger");
|
|
8
|
-
const logger = logger_1.getInstance();
|
|
8
|
+
const logger = (0, logger_1.getInstance)();
|
|
9
9
|
function createConfig(context, opts) {
|
|
10
10
|
// structure of config object to be returned
|
|
11
11
|
const config = {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import
|
|
3
|
-
import type { Request } from '../types';
|
|
2
|
+
import type * as http from 'http';
|
|
4
3
|
/**
|
|
5
4
|
* Fix proxied body if bodyParser is involved.
|
|
6
5
|
*/
|
|
7
|
-
export declare function fixRequestBody(proxyReq: ClientRequest, req:
|
|
6
|
+
export declare function fixRequestBody(proxyReq: http.ClientRequest, req: http.IncomingMessage): void;
|
|
@@ -6,7 +6,8 @@ const querystring = require("querystring");
|
|
|
6
6
|
* Fix proxied body if bodyParser is involved.
|
|
7
7
|
*/
|
|
8
8
|
function fixRequestBody(proxyReq, req) {
|
|
9
|
-
|
|
9
|
+
const requestBody = req.body;
|
|
10
|
+
if (!requestBody) {
|
|
10
11
|
return;
|
|
11
12
|
}
|
|
12
13
|
const contentType = proxyReq.getHeader('Content-Type');
|
|
@@ -15,11 +16,11 @@ function fixRequestBody(proxyReq, req) {
|
|
|
15
16
|
proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData));
|
|
16
17
|
proxyReq.write(bodyData);
|
|
17
18
|
};
|
|
18
|
-
if (contentType.includes('application/json')) {
|
|
19
|
-
writeBody(JSON.stringify(
|
|
19
|
+
if (contentType && contentType.includes('application/json')) {
|
|
20
|
+
writeBody(JSON.stringify(requestBody));
|
|
20
21
|
}
|
|
21
22
|
if (contentType === 'application/x-www-form-urlencoded') {
|
|
22
|
-
writeBody(querystring.stringify(
|
|
23
|
+
writeBody(querystring.stringify(requestBody));
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
26
|
exports.fixRequestBody = 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");
|
|
@@ -19,15 +10,15 @@ const PathRewriter = require("./path-rewriter");
|
|
|
19
10
|
const Router = require("./router");
|
|
20
11
|
class HttpProxyMiddleware {
|
|
21
12
|
constructor(context, opts) {
|
|
22
|
-
this.logger = logger_1.getInstance();
|
|
13
|
+
this.logger = (0, logger_1.getInstance)();
|
|
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
|
-
const arrow = logger_1.getArrow(originalPath, req.url, this.proxyOptions.target, newProxyOptions.target);
|
|
101
|
+
const arrow = (0, 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)
|
|
@@ -144,7 +135,7 @@ class HttpProxyMiddleware {
|
|
|
144
135
|
const errReference = 'https://nodejs.org/api/errors.html#errors_common_system_errors'; // link to Node Common Systems Errors page
|
|
145
136
|
this.logger.error(errorMessage, requestHref, targetHref, err.code || err, errReference);
|
|
146
137
|
};
|
|
147
|
-
this.config = config_factory_1.createConfig(context, opts);
|
|
138
|
+
this.config = (0, config_factory_1.createConfig)(context, opts);
|
|
148
139
|
this.proxyOptions = this.config.options;
|
|
149
140
|
// create proxy
|
|
150
141
|
this.proxy = httpProxy.createProxyServer({});
|
package/dist/path-rewriter.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.createPathRewriter = void 0;
|
|
|
4
4
|
const isPlainObj = require("is-plain-obj");
|
|
5
5
|
const errors_1 = require("./errors");
|
|
6
6
|
const logger_1 = require("./logger");
|
|
7
|
-
const logger = logger_1.getInstance();
|
|
7
|
+
const logger = (0, logger_1.getInstance)();
|
|
8
8
|
/**
|
|
9
9
|
* Create rewrite function, to cache parsed rewrite rules.
|
|
10
10
|
*
|
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
|
-
const logger = logger_1.getInstance();
|
|
16
|
-
function getTarget(req, config) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return newTarget;
|
|
27
|
-
});
|
|
6
|
+
const logger = (0, logger_1.getInstance)();
|
|
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: Request, res: Response, target?: string | Partial<url.Url>) => void;
|
|
49
|
+
export declare type OnProxyResCallback = (proxyRes: http.IncomingMessage, req: Request, res: Response) => void;
|
|
50
|
+
export declare type OnProxyReqCallback = (proxyReq: http.ClientRequest, req: Request, res: Response, options: httpProxy.ServerOptions) => void;
|
|
51
|
+
export declare type OnProxyReqWsCallback = (proxyReq: http.ClientRequest, req: Request, socket: net.Socket, options: httpProxy.ServerOptions, head: any) => void;
|
|
52
|
+
export declare type OnCloseCallback = (proxyRes: Response, 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.2",
|
|
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",
|
|
@@ -19,8 +19,11 @@
|
|
|
19
19
|
"build": "tsc",
|
|
20
20
|
"pretest": "yarn build",
|
|
21
21
|
"test": "jest",
|
|
22
|
+
"precoverage": "yarn build",
|
|
22
23
|
"coverage": "jest --coverage --coverageReporters=lcov",
|
|
23
|
-
"prepare": "
|
|
24
|
+
"prepare": "husky install",
|
|
25
|
+
"prepack": "yarn build && rm dist/tsconfig.tsbuildinfo",
|
|
26
|
+
"spellcheck": "npx --yes cspell --show-context --show-suggestions '**/*.*'"
|
|
24
27
|
},
|
|
25
28
|
"repository": {
|
|
26
29
|
"type": "git",
|
|
@@ -50,50 +53,48 @@
|
|
|
50
53
|
},
|
|
51
54
|
"homepage": "https://github.com/chimurai/http-proxy-middleware#readme",
|
|
52
55
|
"devDependencies": {
|
|
53
|
-
"@commitlint/cli": "
|
|
54
|
-
"@commitlint/config-conventional": "
|
|
55
|
-
"@types/express": "4.17.
|
|
56
|
-
"@types/is-glob": "
|
|
57
|
-
"@types/jest": "
|
|
58
|
-
"@types/micromatch": "
|
|
59
|
-
"@types/node": "
|
|
60
|
-
"@types/supertest": "
|
|
61
|
-
"@types/ws": "
|
|
62
|
-
"@typescript-eslint/eslint-plugin": "
|
|
63
|
-
"@typescript-eslint/parser": "
|
|
64
|
-
"body-parser": "
|
|
65
|
-
"browser-sync": "
|
|
66
|
-
"connect": "
|
|
67
|
-
"eslint": "
|
|
68
|
-
"eslint-config-prettier": "
|
|
69
|
-
"eslint-plugin-prettier": "
|
|
70
|
-
"express": "
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
"
|
|
56
|
+
"@commitlint/cli": "16.1.0",
|
|
57
|
+
"@commitlint/config-conventional": "16.0.0",
|
|
58
|
+
"@types/express": "4.17.13",
|
|
59
|
+
"@types/is-glob": "4.0.2",
|
|
60
|
+
"@types/jest": "27.4.0",
|
|
61
|
+
"@types/micromatch": "4.0.2",
|
|
62
|
+
"@types/node": "17.0.10",
|
|
63
|
+
"@types/supertest": "2.0.11",
|
|
64
|
+
"@types/ws": "8.2.2",
|
|
65
|
+
"@typescript-eslint/eslint-plugin": "5.10.0",
|
|
66
|
+
"@typescript-eslint/parser": "5.10.0",
|
|
67
|
+
"body-parser": "1.19.1",
|
|
68
|
+
"browser-sync": "2.27.7",
|
|
69
|
+
"connect": "3.7.0",
|
|
70
|
+
"eslint": "8.7.0",
|
|
71
|
+
"eslint-config-prettier": "8.3.0",
|
|
72
|
+
"eslint-plugin-prettier": "4.0.0",
|
|
73
|
+
"express": "4.17.2",
|
|
74
|
+
"get-port": "5.1.1",
|
|
75
|
+
"husky": "7.0.4",
|
|
76
|
+
"jest": "27.4.7",
|
|
77
|
+
"lint-staged": "12.2.2",
|
|
78
|
+
"mockttp": "2.5.1",
|
|
79
|
+
"open": "8.4.0",
|
|
80
|
+
"prettier": "2.5.1",
|
|
81
|
+
"supertest": "6.2.2",
|
|
82
|
+
"ts-jest": "27.1.3",
|
|
83
|
+
"typescript": "4.5.5",
|
|
84
|
+
"ws": "8.4.2"
|
|
81
85
|
},
|
|
82
86
|
"dependencies": {
|
|
83
|
-
"@types/http-proxy": "^1.17.
|
|
87
|
+
"@types/http-proxy": "^1.17.8",
|
|
84
88
|
"http-proxy": "^1.18.1",
|
|
85
89
|
"is-glob": "^4.0.1",
|
|
86
90
|
"is-plain-obj": "^3.0.0",
|
|
87
91
|
"micromatch": "^4.0.2"
|
|
88
92
|
},
|
|
89
|
-
"
|
|
90
|
-
"
|
|
93
|
+
"peerDependencies": {
|
|
94
|
+
"@types/express": "^4.17.13"
|
|
91
95
|
},
|
|
92
|
-
"
|
|
93
|
-
"
|
|
94
|
-
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
|
|
95
|
-
"pre-commit": "lint-staged"
|
|
96
|
-
}
|
|
96
|
+
"engines": {
|
|
97
|
+
"node": ">=12.0.0"
|
|
97
98
|
},
|
|
98
99
|
"commitlint": {
|
|
99
100
|
"extends": [
|
package/CHANGELOG.md
DELETED
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
## [v1.3.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.3.0)
|
|
4
|
-
|
|
5
|
-
- docs(response interceptor): align with nodejs default utf8 ([#567](https://github.com/chimurai/http-proxy-middleware/pull/567))
|
|
6
|
-
- feat: try to proxy body even after body-parser middleware ([#492](https://github.com/chimurai/http-proxy-middleware/pull/492)) ([midgleyc](https://github.com/midgleyc))
|
|
7
|
-
|
|
8
|
-
## [v1.2.1](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.2.1)
|
|
9
|
-
|
|
10
|
-
- fix(response interceptor): proxy original response headers ([#563](https://github.com/chimurai/http-proxy-middleware/pull/563))
|
|
11
|
-
|
|
12
|
-
## [v1.2.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.2.0)
|
|
13
|
-
|
|
14
|
-
- feat(handler): response interceptor ([#520](https://github.com/chimurai/http-proxy-middleware/pull/520))
|
|
15
|
-
- fix(log error): handle undefined target when websocket errors ([#527](https://github.com/chimurai/http-proxy-middleware/pull/527))
|
|
16
|
-
|
|
17
|
-
## [v1.1.2](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.1.2)
|
|
18
|
-
|
|
19
|
-
- fix(log error): handle optional target ([#523](https://github.com/chimurai/http-proxy-middleware/pull/523))
|
|
20
|
-
|
|
21
|
-
## [v1.1.1](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.1.1)
|
|
22
|
-
|
|
23
|
-
- fix(error handler): re-throw http-proxy missing target error ([#517](https://github.com/chimurai/http-proxy-middleware/pull/517))
|
|
24
|
-
- refactor(dependency): remove `camelcase`
|
|
25
|
-
- fix(option): optional `target` when `router` is used ([#512](https://github.com/chimurai/http-proxy-middleware/pull/512))
|
|
26
|
-
|
|
27
|
-
## [v1.1.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.1.0)
|
|
28
|
-
|
|
29
|
-
- fix(errorHandler): fix confusing error message ([#509](https://github.com/chimurai/http-proxy-middleware/pull/509))
|
|
30
|
-
- fix(proxy): close proxy when server closes ([#508](https://github.com/chimurai/http-proxy-middleware/pull/508))
|
|
31
|
-
- 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))
|
|
32
|
-
- fix(ETIMEDOUT): return 504 on ETIMEDOUT ([#480](https://github.com/chimurai/http-proxy-middleware/pull/480)) ([aremishevsky](https://github.com/aremishevsky))
|
|
33
|
-
|
|
34
|
-
## [v1.0.6](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.0.6)
|
|
35
|
-
|
|
36
|
-
- chore(deps): lodash 4.17.20 ([#475](https://github.com/chimurai/http-proxy-middleware/pull/475))
|
|
37
|
-
|
|
38
|
-
## [v1.0.5](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.0.6)
|
|
39
|
-
|
|
40
|
-
- chore(deps): lodash 4.17.19 ([#454](https://github.com/chimurai/http-proxy-middleware/pull/454))
|
|
41
|
-
|
|
42
|
-
## [v1.0.4](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.0.4)
|
|
43
|
-
|
|
44
|
-
- chore(deps): http-proxy 1.18.1 ([#442](https://github.com/chimurai/http-proxy-middleware/pull/442))
|
|
45
|
-
|
|
46
|
-
## [v1.0.3](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.0.3)
|
|
47
|
-
|
|
48
|
-
- build(package): exclude build artifact tsconfig.tsbuildinfo ([#415](https://github.com/chimurai/http-proxy-middleware/pull/415))
|
|
49
|
-
|
|
50
|
-
## [v1.0.2](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.0.2)
|
|
51
|
-
|
|
52
|
-
- fix(router): handle rejected promise in custom router ([#410](https://github.com/chimurai/http-proxy-middleware/pull/413)) ([bforbis](https://github.com/bforbis))
|
|
53
|
-
|
|
54
|
-
## [v1.0.1](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.0.1)
|
|
55
|
-
|
|
56
|
-
- fix(typescript): fix proxyRes and router types ([#410](https://github.com/chimurai/http-proxy-middleware/issues/410)) ([dylang](https://github.com/dylang))
|
|
57
|
-
|
|
58
|
-
## [v1.0.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.0.0)
|
|
59
|
-
|
|
60
|
-
- 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))
|
|
61
|
-
- feat(typescript): export http-proxy-middleware types ([#400](https://github.com/chimurai/http-proxy-middleware/issues/400))
|
|
62
|
-
- fix(typescript): ES6 target - TS1192 ([#400](https://github.com/chimurai/http-proxy-middleware/issues/400#issuecomment-587064349))
|
|
63
|
-
|
|
64
|
-
## [v0.21.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.21.0)
|
|
65
|
-
|
|
66
|
-
- feat(http-proxy): bump to v1.18.0
|
|
67
|
-
- feat: async router ([#379](https://github.com/chimurai/http-proxy-middleware/issues/379)) ([LiranBri](https://github.com/LiranBri))
|
|
68
|
-
- feat(typescript): types support ([#369](https://github.com/chimurai/http-proxy-middleware/pull/369))
|
|
69
|
-
- feat: async pathRewrite ([#397](https://github.com/chimurai/http-proxy-middleware/pull/397)) ([rsethc](https://github.com/rsethc))
|
|
70
|
-
|
|
71
|
-
## [v0.20.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.20.0)
|
|
72
|
-
|
|
73
|
-
- fix(ws): concurrent websocket requests do not get upgraded ([#335](https://github.com/chimurai/http-proxy-middleware/issues/335))
|
|
74
|
-
- chore: drop node 6 (BREAKING CHANGE)
|
|
75
|
-
- chore: update to micromatch@4 ([BREAKING CHANGE](https://github.com/micromatch/micromatch/blob/master/CHANGELOG.md#400---2019-03-20))
|
|
76
|
-
- chore: update dev dependencies
|
|
77
|
-
- refactor: migrate to typescript ([#328](https://github.com/chimurai/http-proxy-middleware/pull/328))
|
|
78
|
-
- feat(middleware): Promise / async support ([#328](https://github.com/chimurai/http-proxy-middleware/pull/328/files#diff-7890bfeb41abb0fc0ef2670749c84077R50))
|
|
79
|
-
- refactor: remove legacy options `proxyHost` and `proxyTable` (BREAKING CHANGE)
|
|
80
|
-
|
|
81
|
-
## [v0.19.1](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.19.1)
|
|
82
|
-
|
|
83
|
-
- fix(log): handle case when error code is missing ([#303](https://github.com/chimurai/http-proxy-middleware/pull/303))
|
|
84
|
-
|
|
85
|
-
## [v0.19.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.19.0)
|
|
86
|
-
|
|
87
|
-
- feat(http-proxy): bump to v1.17.0 ([#261](https://github.com/chimurai/http-proxy-middleware/pull/261))
|
|
88
|
-
|
|
89
|
-
## [v0.18.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.18.0)
|
|
90
|
-
|
|
91
|
-
- 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))
|
|
92
|
-
- test(node): drop node 0.x support ([#212](https://github.com/chimurai/http-proxy-middleware/pull/212))
|
|
93
|
-
|
|
94
|
-
## [v0.17.4](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.17.4)
|
|
95
|
-
|
|
96
|
-
- 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))
|
|
97
|
-
|
|
98
|
-
## [v0.17.3](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.17.3)
|
|
99
|
-
|
|
100
|
-
- 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))
|
|
101
|
-
|
|
102
|
-
## [v0.17.2](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.17.2)
|
|
103
|
-
|
|
104
|
-
- 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))
|
|
105
|
-
- feat(pathRewrite): path can be empty string. ([#110](https://github.com/chimurai/http-proxy-middleware/pull/110)) ([sunnylqm](https://github.com/sunnylqm))
|
|
106
|
-
- 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))
|
|
107
|
-
- chore(package.json): reduce package size. ([#109](https://github.com/chimurai/http-proxy-middleware/pull/109))
|
|
108
|
-
|
|
109
|
-
## [v0.17.1](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.17.1)
|
|
110
|
-
|
|
111
|
-
- fix(Express sub Router): 404 on non-proxy routes ([#94](https://github.com/chimurai/http-proxy-middleware/issues/94))
|
|
112
|
-
|
|
113
|
-
## [v0.17.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.17.0)
|
|
114
|
-
|
|
115
|
-
- fix(context matching): Use [RFC 3986 path](https://tools.ietf.org/html/rfc3986#section-3.3) in context matching. (excludes query parameters)
|
|
116
|
-
|
|
117
|
-
## [v0.16.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.16.0)
|
|
118
|
-
|
|
119
|
-
- deprecated(proxyTable): renamed `proxyTable` to `router`.
|
|
120
|
-
- feat(router): support for custom `router` function.
|
|
121
|
-
|
|
122
|
-
## [v0.15.2](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.15.2)
|
|
123
|
-
|
|
124
|
-
- fix(websocket): fixes websocket upgrade.
|
|
125
|
-
|
|
126
|
-
## [v0.15.1](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.15.1)
|
|
127
|
-
|
|
128
|
-
- feat(pathRewrite): expose `req` object to pathRewrite function.
|
|
129
|
-
- fix(websocket): fixes websocket upgrade when both config.ws and external .upgrade() are used.
|
|
130
|
-
|
|
131
|
-
## [v0.15.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.15.0)
|
|
132
|
-
|
|
133
|
-
- feat(pathRewrite): support for custom pathRewrite function.
|
|
134
|
-
|
|
135
|
-
## [v0.14.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.14.0)
|
|
136
|
-
|
|
137
|
-
- feat(proxy): support proxy creation without context.
|
|
138
|
-
- fix(connect mounting): use connect's `path` configuration to mount proxy.
|
|
139
|
-
|
|
140
|
-
## [v0.13.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.13.0)
|
|
141
|
-
|
|
142
|
-
- feat(context): custom context matcher; when simple `path` matching is not sufficient.
|
|
143
|
-
|
|
144
|
-
## [v0.12.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.12.0)
|
|
145
|
-
|
|
146
|
-
- add option `onProxyReqWs` (subscribe to http-proxy `proxyReqWs` event)
|
|
147
|
-
- add option `onOpen` (subscribe to http-proxy `open` event)
|
|
148
|
-
- add option `onClose` (subscribe to http-proxy `close` event)
|
|
149
|
-
|
|
150
|
-
## [v0.11.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.11.0)
|
|
151
|
-
|
|
152
|
-
- improved logging
|
|
153
|
-
|
|
154
|
-
## [v0.10.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.10.0)
|
|
155
|
-
|
|
156
|
-
- feat(proxyTable) - added proxyTable support for WebSockets.
|
|
157
|
-
- fixed(proxyTable) - ensure original path (not rewritten path) is being used when `proxyTable` is used in conjunction with `pathRewrite`.
|
|
158
|
-
|
|
159
|
-
## [v0.9.1](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.9.1)
|
|
160
|
-
|
|
161
|
-
- fix server crash when socket error not handled correctly.
|
|
162
|
-
|
|
163
|
-
## [v0.9.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.9.0)
|
|
164
|
-
|
|
165
|
-
- support subscribing to http-proxy `proxyReq` event ([trbngr](https://github.com/trbngr))
|
|
166
|
-
- add `logLevel` and `logProvider` support
|
|
167
|
-
|
|
168
|
-
## [v0.8.2](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.8.2)
|
|
169
|
-
|
|
170
|
-
- fix proxyError handler ([mTazelaar](https://github.com/mTazelaar))
|
|
171
|
-
|
|
172
|
-
## [v0.8.1](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.8.1)
|
|
173
|
-
|
|
174
|
-
- fix pathRewrite when `agent` is configured
|
|
175
|
-
|
|
176
|
-
## [v0.8.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.8.0)
|
|
177
|
-
|
|
178
|
-
- support external websocket upgrade
|
|
179
|
-
- fix websocket shorthand
|
|
180
|
-
|
|
181
|
-
## [v0.7.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.7.0)
|
|
182
|
-
|
|
183
|
-
- support shorthand syntax
|
|
184
|
-
- fix express/connect mounting
|
|
185
|
-
|
|
186
|
-
## [v0.6.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.6.0)
|
|
187
|
-
|
|
188
|
-
- support proxyTable
|
|
189
|
-
|
|
190
|
-
## [v0.5.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.5.0)
|
|
191
|
-
|
|
192
|
-
- support subscribing to http-proxy `error` event
|
|
193
|
-
- support subscribing to http-proxy `proxyRes` event
|
|
194
|
-
|
|
195
|
-
## [v0.4.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.4.0)
|
|
196
|
-
|
|
197
|
-
- support websocket
|
|
198
|
-
|
|
199
|
-
## [v0.3.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.3.0)
|
|
200
|
-
|
|
201
|
-
- support wildcard / glob
|
|
202
|
-
|
|
203
|
-
## [v0.2.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.2.0)
|
|
204
|
-
|
|
205
|
-
- support multiple paths
|
|
206
|
-
|
|
207
|
-
## [v0.1.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.1.0)
|
|
208
|
-
|
|
209
|
-
- support path rewrite
|
|
210
|
-
- deprecate proxyHost option
|
|
211
|
-
|
|
212
|
-
## [v0.0.5](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.0.5)
|
|
213
|
-
|
|
214
|
-
- initial release
|