http-proxy-middleware 2.0.1 → 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 +6 -3
- package/dist/_handlers.js +2 -2
- package/dist/config-factory.js +1 -1
- package/dist/handlers/fix-request-body.js +1 -1
- package/dist/http-proxy-middleware.js +3 -3
- package/dist/path-rewriter.js +1 -1
- package/dist/router.js +1 -1
- package/dist/types.d.ts +5 -5
- package/package.json +37 -32
package/README.md
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
[](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 = {
|
|
@@ -7,7 +7,7 @@ const querystring = require("querystring");
|
|
|
7
7
|
*/
|
|
8
8
|
function fixRequestBody(proxyReq, req) {
|
|
9
9
|
const requestBody = req.body;
|
|
10
|
-
if (!requestBody
|
|
10
|
+
if (!requestBody) {
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
13
|
const contentType = proxyReq.getHeader('Content-Type');
|
|
@@ -10,7 +10,7 @@ const PathRewriter = require("./path-rewriter");
|
|
|
10
10
|
const Router = require("./router");
|
|
11
11
|
class HttpProxyMiddleware {
|
|
12
12
|
constructor(context, opts) {
|
|
13
|
-
this.logger = logger_1.getInstance();
|
|
13
|
+
this.logger = (0, logger_1.getInstance)();
|
|
14
14
|
this.wsInternalSubscribed = false;
|
|
15
15
|
this.serverOnCloseSubscribed = false;
|
|
16
16
|
// https://github.com/Microsoft/TypeScript/wiki/'this'-in-TypeScript#red-flags-for-this
|
|
@@ -98,7 +98,7 @@ class HttpProxyMiddleware {
|
|
|
98
98
|
await this.applyPathRewrite(req, this.pathRewriter);
|
|
99
99
|
// debug logging for both http(s) and websockets
|
|
100
100
|
if (this.proxyOptions.logLevel === 'debug') {
|
|
101
|
-
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);
|
|
102
102
|
this.logger.debug('[HPM] %s %s %s %s', req.method, originalPath, arrow, newProxyOptions.target);
|
|
103
103
|
}
|
|
104
104
|
return newProxyOptions;
|
|
@@ -135,7 +135,7 @@ class HttpProxyMiddleware {
|
|
|
135
135
|
const errReference = 'https://nodejs.org/api/errors.html#errors_common_system_errors'; // link to Node Common Systems Errors page
|
|
136
136
|
this.logger.error(errorMessage, requestHref, targetHref, err.code || err, errReference);
|
|
137
137
|
};
|
|
138
|
-
this.config = config_factory_1.createConfig(context, opts);
|
|
138
|
+
this.config = (0, config_factory_1.createConfig)(context, opts);
|
|
139
139
|
this.proxyOptions = this.config.options;
|
|
140
140
|
// create proxy
|
|
141
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
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getTarget = void 0;
|
|
4
4
|
const isPlainObj = require("is-plain-obj");
|
|
5
5
|
const logger_1 = require("./logger");
|
|
6
|
-
const logger = logger_1.getInstance();
|
|
6
|
+
const logger = (0, logger_1.getInstance)();
|
|
7
7
|
async function getTarget(req, config) {
|
|
8
8
|
let newTarget;
|
|
9
9
|
const router = config.router;
|
package/dist/types.d.ts
CHANGED
|
@@ -45,10 +45,10 @@ export declare type LogProviderCallback = (provider: LogProvider) => LogProvider
|
|
|
45
45
|
* Use types based on the events listeners from http-proxy
|
|
46
46
|
* https://github.com/DefinitelyTyped/DefinitelyTyped/blob/51504fd999031b7f025220fab279f1b2155cbaff/types/http-proxy/index.d.ts
|
|
47
47
|
*/
|
|
48
|
-
export declare type OnErrorCallback = (err: Error, req:
|
|
49
|
-
export declare type OnProxyResCallback = (proxyRes: http.IncomingMessage, req:
|
|
50
|
-
export declare type OnProxyReqCallback = (proxyReq: http.ClientRequest, req:
|
|
51
|
-
export declare type OnProxyReqWsCallback = (proxyReq: http.ClientRequest, req:
|
|
52
|
-
export declare type OnCloseCallback = (proxyRes:
|
|
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
53
|
export declare type OnOpenCallback = (proxySocket: net.Socket) => void;
|
|
54
54
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "http-proxy-middleware",
|
|
3
|
-
"version": "2.0.
|
|
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",
|
|
@@ -21,7 +21,9 @@
|
|
|
21
21
|
"test": "jest",
|
|
22
22
|
"precoverage": "yarn build",
|
|
23
23
|
"coverage": "jest --coverage --coverageReporters=lcov",
|
|
24
|
-
"prepare": "husky install
|
|
24
|
+
"prepare": "husky install",
|
|
25
|
+
"prepack": "yarn build && rm dist/tsconfig.tsbuildinfo",
|
|
26
|
+
"spellcheck": "npx --yes cspell --show-context --show-suggestions '**/*.*'"
|
|
25
27
|
},
|
|
26
28
|
"repository": {
|
|
27
29
|
"type": "git",
|
|
@@ -51,43 +53,46 @@
|
|
|
51
53
|
},
|
|
52
54
|
"homepage": "https://github.com/chimurai/http-proxy-middleware#readme",
|
|
53
55
|
"devDependencies": {
|
|
54
|
-
"@commitlint/cli": "
|
|
55
|
-
"@commitlint/config-conventional": "
|
|
56
|
-
"@types/express": "4.17.
|
|
57
|
-
"@types/is-glob": "
|
|
58
|
-
"@types/jest": "
|
|
59
|
-
"@types/micromatch": "
|
|
60
|
-
"@types/node": "
|
|
61
|
-
"@types/supertest": "
|
|
62
|
-
"@types/ws": "
|
|
63
|
-
"@typescript-eslint/eslint-plugin": "
|
|
64
|
-
"@typescript-eslint/parser": "
|
|
65
|
-
"body-parser": "
|
|
66
|
-
"browser-sync": "
|
|
67
|
-
"connect": "
|
|
68
|
-
"eslint": "
|
|
69
|
-
"eslint-config-prettier": "
|
|
70
|
-
"eslint-plugin-prettier": "
|
|
71
|
-
"express": "
|
|
72
|
-
"get-port": "
|
|
73
|
-
"husky": "
|
|
74
|
-
"jest": "
|
|
75
|
-
"lint-staged": "
|
|
76
|
-
"mockttp": "
|
|
77
|
-
"open": "
|
|
78
|
-
"prettier": "
|
|
79
|
-
"supertest": "
|
|
80
|
-
"ts-jest": "
|
|
81
|
-
"typescript": "
|
|
82
|
-
"ws": "
|
|
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"
|
|
83
85
|
},
|
|
84
86
|
"dependencies": {
|
|
85
|
-
"@types/http-proxy": "^1.17.
|
|
87
|
+
"@types/http-proxy": "^1.17.8",
|
|
86
88
|
"http-proxy": "^1.18.1",
|
|
87
89
|
"is-glob": "^4.0.1",
|
|
88
90
|
"is-plain-obj": "^3.0.0",
|
|
89
91
|
"micromatch": "^4.0.2"
|
|
90
92
|
},
|
|
93
|
+
"peerDependencies": {
|
|
94
|
+
"@types/express": "^4.17.13"
|
|
95
|
+
},
|
|
91
96
|
"engines": {
|
|
92
97
|
"node": ">=12.0.0"
|
|
93
98
|
},
|