http-proxy-middleware 1.0.1 → 1.0.5
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/CHANGELOG.md +16 -0
- package/README.md +8 -8
- package/dist/config-factory.js +2 -1
- package/dist/context-matcher.js +1 -0
- package/dist/errors.js +1 -0
- package/dist/handlers.js +1 -0
- package/dist/http-proxy-middleware.js +9 -3
- package/dist/index.js +1 -0
- package/dist/logger.js +2 -1
- package/dist/path-rewriter.js +3 -2
- package/dist/router.js +1 -0
- package/package.json +21 -26
- package/dist/tsconfig.tsbuildinfo +0 -2911
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [v1.0.5](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.0.5)
|
|
4
|
+
|
|
5
|
+
- chore(deps): lodash 4.17.19 ([#454](https://github.com/chimurai/http-proxy-middleware/pull/454))
|
|
6
|
+
|
|
7
|
+
## [v1.0.4](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.0.4)
|
|
8
|
+
|
|
9
|
+
- chore(deps): http-proxy 1.18.1 ([#442](https://github.com/chimurai/http-proxy-middleware/pull/442))
|
|
10
|
+
|
|
11
|
+
## [v1.0.3](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.0.3)
|
|
12
|
+
|
|
13
|
+
- build(package): exclude build artifact tsconfig.tsbuildinfo ([#415](https://github.com/chimurai/http-proxy-middleware/pull/415))
|
|
14
|
+
|
|
15
|
+
## [v1.0.2](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.0.2)
|
|
16
|
+
|
|
17
|
+
- fix(router): handle rejected promise in custom router ([#410](https://github.com/chimurai/http-proxy-middleware/pull/413)) ([bforbis](https://github.com/bforbis))
|
|
18
|
+
|
|
3
19
|
## [v1.0.1](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.0.1)
|
|
4
20
|
|
|
5
21
|
- fix(typescript): fix proxyRes and router types ([#410](https://github.com/chimurai/http-proxy-middleware/issues/410)) ([dylang](https://github.com/dylang))
|
package/README.md
CHANGED
|
@@ -132,13 +132,13 @@ const options = {
|
|
|
132
132
|
ws: true, // proxy websockets
|
|
133
133
|
pathRewrite: {
|
|
134
134
|
'^/api/old-path': '/api/new-path', // rewrite path
|
|
135
|
-
'^/api/remove/path': '/path' // remove base path
|
|
135
|
+
'^/api/remove/path': '/path', // remove base path
|
|
136
136
|
},
|
|
137
137
|
router: {
|
|
138
138
|
// when request.headers.host == 'dev.localhost:3000',
|
|
139
139
|
// override target 'http://www.example.org' to 'http://localhost:8000'
|
|
140
|
-
'dev.localhost:3000': 'http://localhost:8000'
|
|
141
|
-
}
|
|
140
|
+
'dev.localhost:3000': 'http://localhost:8000',
|
|
141
|
+
},
|
|
142
142
|
};
|
|
143
143
|
|
|
144
144
|
// create the proxy (without context)
|
|
@@ -194,12 +194,12 @@ Providing an alternative way to decide which requests should be proxied; In case
|
|
|
194
194
|
/**
|
|
195
195
|
* @return {Boolean}
|
|
196
196
|
*/
|
|
197
|
-
const filter = function(pathname, req) {
|
|
197
|
+
const filter = function (pathname, req) {
|
|
198
198
|
return pathname.match('^/api') && req.method === 'GET';
|
|
199
199
|
};
|
|
200
200
|
|
|
201
201
|
const apiProxy = createProxyMiddleware(filter, {
|
|
202
|
-
target: 'http://www.example.org'
|
|
202
|
+
target: 'http://www.example.org',
|
|
203
203
|
});
|
|
204
204
|
```
|
|
205
205
|
|
|
@@ -285,7 +285,7 @@ Providing an alternative way to decide which requests should be proxied; In case
|
|
|
285
285
|
debug: logger.debug,
|
|
286
286
|
info: logger.info,
|
|
287
287
|
warn: logger.warn,
|
|
288
|
-
error: logger.error
|
|
288
|
+
error: logger.error,
|
|
289
289
|
};
|
|
290
290
|
return myCustomProvider;
|
|
291
291
|
}
|
|
@@ -300,7 +300,7 @@ Subscribe to [http-proxy events](https://github.com/nodejitsu/node-http-proxy#li
|
|
|
300
300
|
```javascript
|
|
301
301
|
function onError(err, req, res) {
|
|
302
302
|
res.writeHead(500, {
|
|
303
|
-
'Content-Type': 'text/plain'
|
|
303
|
+
'Content-Type': 'text/plain',
|
|
304
304
|
});
|
|
305
305
|
res.end('Something went wrong. And we are reporting a custom error message.');
|
|
306
306
|
}
|
|
@@ -417,7 +417,7 @@ The following options are provided by the underlying [http-proxy](https://github
|
|
|
417
417
|
res,
|
|
418
418
|
{
|
|
419
419
|
target: 'http://localhost:4003/',
|
|
420
|
-
buffer: streamify(req.rawBody)
|
|
420
|
+
buffer: streamify(req.rawBody),
|
|
421
421
|
},
|
|
422
422
|
next
|
|
423
423
|
);
|
package/dist/config-factory.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createConfig = void 0;
|
|
3
4
|
const _ = require("lodash");
|
|
4
5
|
const url = require("url");
|
|
5
6
|
const errors_1 = require("./errors");
|
|
@@ -9,7 +10,7 @@ function createConfig(context, opts) {
|
|
|
9
10
|
// structure of config object to be returned
|
|
10
11
|
const config = {
|
|
11
12
|
context: undefined,
|
|
12
|
-
options: {}
|
|
13
|
+
options: {},
|
|
13
14
|
};
|
|
14
15
|
// app.use('/api', proxy({target:'http://localhost:9000'}));
|
|
15
16
|
if (isContextless(context, opts)) {
|
package/dist/context-matcher.js
CHANGED
package/dist/errors.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ERRORS = void 0;
|
|
3
4
|
var ERRORS;
|
|
4
5
|
(function (ERRORS) {
|
|
5
6
|
ERRORS["ERR_CONFIG_FACTORY_TARGET_MISSING"] = "[HPM] Missing \"target\" option. Example: {target: \"http://www.example.org\"}";
|
package/dist/handlers.js
CHANGED
|
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.HttpProxyMiddleware = void 0;
|
|
12
13
|
const httpProxy = require("http-proxy");
|
|
13
14
|
const _ = require("lodash");
|
|
14
15
|
const config_factory_1 = require("./config-factory");
|
|
@@ -24,8 +25,13 @@ class HttpProxyMiddleware {
|
|
|
24
25
|
// https://github.com/Microsoft/TypeScript/wiki/'this'-in-TypeScript#red-flags-for-this
|
|
25
26
|
this.middleware = (req, res, next) => __awaiter(this, void 0, void 0, function* () {
|
|
26
27
|
if (this.shouldProxy(this.config.context, req)) {
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
try {
|
|
29
|
+
const activeProxyOptions = yield this.prepareProxyRequest(req);
|
|
30
|
+
this.proxy.web(req, res, activeProxyOptions);
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
next(err);
|
|
34
|
+
}
|
|
29
35
|
}
|
|
30
36
|
else {
|
|
31
37
|
next();
|
|
@@ -35,7 +41,7 @@ class HttpProxyMiddleware {
|
|
|
35
41
|
this.catchUpgradeRequest(req.connection.server);
|
|
36
42
|
}
|
|
37
43
|
});
|
|
38
|
-
this.catchUpgradeRequest = server => {
|
|
44
|
+
this.catchUpgradeRequest = (server) => {
|
|
39
45
|
if (!this.wsInternalSubscribed) {
|
|
40
46
|
server.on('upgrade', this.handleUpgrade);
|
|
41
47
|
// prevent duplicate upgrade handling;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createProxyMiddleware = void 0;
|
|
3
4
|
const http_proxy_middleware_1 = require("./http-proxy-middleware");
|
|
4
5
|
function createProxyMiddleware(context, options) {
|
|
5
6
|
const { middleware } = new http_proxy_middleware_1.HttpProxyMiddleware(context, options);
|
package/dist/logger.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getArrow = exports.getInstance = void 0;
|
|
3
4
|
const _ = require("lodash");
|
|
4
5
|
const util = require("util");
|
|
5
6
|
let loggerInstance;
|
|
@@ -9,7 +10,7 @@ const defaultProvider = {
|
|
|
9
10
|
debug: console.log,
|
|
10
11
|
info: console.info,
|
|
11
12
|
warn: console.warn,
|
|
12
|
-
error: console.error
|
|
13
|
+
error: console.error,
|
|
13
14
|
};
|
|
14
15
|
// log level 'weight'
|
|
15
16
|
var LEVELS;
|
package/dist/path-rewriter.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPathRewriter = void 0;
|
|
3
4
|
const _ = require("lodash");
|
|
4
5
|
const errors_1 = require("./errors");
|
|
5
6
|
const logger_1 = require("./logger");
|
|
@@ -25,7 +26,7 @@ function createPathRewriter(rewriteConfig) {
|
|
|
25
26
|
}
|
|
26
27
|
function rewritePath(path) {
|
|
27
28
|
let result = path;
|
|
28
|
-
_.forEach(rulesCache, rule => {
|
|
29
|
+
_.forEach(rulesCache, (rule) => {
|
|
29
30
|
if (rule.regex.test(path)) {
|
|
30
31
|
result = result.replace(rule.regex, rule.value);
|
|
31
32
|
logger.debug('[HPM] Rewriting path from "%s" to "%s"', path, result);
|
|
@@ -58,7 +59,7 @@ function parsePathRewriteRules(rewriteConfig) {
|
|
|
58
59
|
_.forIn(rewriteConfig, (value, key) => {
|
|
59
60
|
rules.push({
|
|
60
61
|
regex: new RegExp(key),
|
|
61
|
-
value: rewriteConfig[key]
|
|
62
|
+
value: rewriteConfig[key],
|
|
62
63
|
});
|
|
63
64
|
logger.info('[HPM] Proxy rewrite rule created: "%s" ~> "%s"', key, rewriteConfig[key]);
|
|
64
65
|
});
|
package/dist/router.js
CHANGED
|
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getTarget = void 0;
|
|
12
13
|
const _ = require("lodash");
|
|
13
14
|
const logger_1 = require("./logger");
|
|
14
15
|
const logger = logger_1.getInstance();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "http-proxy-middleware",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
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",
|
|
@@ -16,12 +16,8 @@
|
|
|
16
16
|
"build": "tsc",
|
|
17
17
|
"pretest": "yarn build",
|
|
18
18
|
"test": "jest",
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"precoveralls": "yarn clean && yarn build",
|
|
22
|
-
"coveralls": "jest --coverage --coverageReporters=text-lcov | coveralls",
|
|
23
|
-
"postcoveralls": "yarn clean",
|
|
24
|
-
"prepare": "yarn clean && yarn build"
|
|
19
|
+
"coverage": "jest --coverage --coverageReporters=lcov",
|
|
20
|
+
"prepare": "yarn clean && yarn build && rm dist/tsconfig.tsbuildinfo"
|
|
25
21
|
},
|
|
26
22
|
"repository": {
|
|
27
23
|
"type": "git",
|
|
@@ -52,35 +48,34 @@
|
|
|
52
48
|
"devDependencies": {
|
|
53
49
|
"@commitlint/cli": "^8.3.5",
|
|
54
50
|
"@commitlint/config-conventional": "^8.3.4",
|
|
55
|
-
"@types/express": "^4.17.
|
|
51
|
+
"@types/express": "^4.17.3",
|
|
56
52
|
"@types/is-glob": "^4.0.1",
|
|
57
|
-
"@types/jest": "^25.
|
|
58
|
-
"@types/lodash": "^4.14.
|
|
53
|
+
"@types/jest": "^25.2.3",
|
|
54
|
+
"@types/lodash": "^4.14.151",
|
|
59
55
|
"@types/micromatch": "^4.0.1",
|
|
60
|
-
"@types/node": "^
|
|
61
|
-
"@types/supertest": "^2.0.
|
|
56
|
+
"@types/node": "^14.0.3",
|
|
57
|
+
"@types/supertest": "^2.0.9",
|
|
62
58
|
"browser-sync": "^2.26.7",
|
|
63
59
|
"connect": "^3.7.0",
|
|
64
|
-
"coveralls": "^3.0.5",
|
|
65
60
|
"express": "^4.17.1",
|
|
66
|
-
"husky": "^4.2.
|
|
67
|
-
"jest": "^
|
|
68
|
-
"lint-staged": "^10.
|
|
69
|
-
"mockttp": "^0.
|
|
70
|
-
"open": "^7.0.
|
|
71
|
-
"prettier": "^
|
|
61
|
+
"husky": "^4.2.5",
|
|
62
|
+
"jest": "^26.0.1",
|
|
63
|
+
"lint-staged": "^10.2.4",
|
|
64
|
+
"mockttp": "^0.20.1",
|
|
65
|
+
"open": "^7.0.4",
|
|
66
|
+
"prettier": "^2.0.5",
|
|
72
67
|
"supertest": "^4.0.2",
|
|
73
|
-
"ts-jest": "^
|
|
74
|
-
"tslint": "^6.
|
|
68
|
+
"ts-jest": "^26.0.0",
|
|
69
|
+
"tslint": "^6.1.2",
|
|
75
70
|
"tslint-config-prettier": "^1.18.0",
|
|
76
|
-
"typescript": "^3.
|
|
77
|
-
"ws": "^7.
|
|
71
|
+
"typescript": "^3.9.2",
|
|
72
|
+
"ws": "^7.3.0"
|
|
78
73
|
},
|
|
79
74
|
"dependencies": {
|
|
80
|
-
"@types/http-proxy": "^1.17.
|
|
81
|
-
"http-proxy": "^1.18.
|
|
75
|
+
"@types/http-proxy": "^1.17.4",
|
|
76
|
+
"http-proxy": "^1.18.1",
|
|
82
77
|
"is-glob": "^4.0.1",
|
|
83
|
-
"lodash": "^4.17.
|
|
78
|
+
"lodash": "^4.17.19",
|
|
84
79
|
"micromatch": "^4.0.2"
|
|
85
80
|
},
|
|
86
81
|
"engines": {
|