http-proxy-middleware 1.0.0 → 1.0.4
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 +17 -1
- package/README.md +18 -10
- package/dist/config-factory.js +1 -1
- package/dist/http-proxy-middleware.js +8 -3
- package/dist/logger.js +1 -1
- package/dist/path-rewriter.js +2 -2
- package/dist/types.d.ts +3 -3
- package/package.json +29 -29
package/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [v1.0.4](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.0.4)
|
|
4
|
+
|
|
5
|
+
- chore(deps): http-proxy 1.18.1 ([#442](https://github.com/chimurai/http-proxy-middleware/pull/442))
|
|
6
|
+
|
|
7
|
+
## [v1.0.3](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.0.3)
|
|
8
|
+
|
|
9
|
+
- build(package): exclude build artifact tsconfig.tsbuildinfo ([#415](https://github.com/chimurai/http-proxy-middleware/pull/415))
|
|
10
|
+
|
|
11
|
+
## [v1.0.2](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.0.2)
|
|
12
|
+
|
|
13
|
+
- fix(router): handle rejected promise in custom router ([#410](https://github.com/chimurai/http-proxy-middleware/pull/413)) ([bforbis](https://github.com/bforbis))
|
|
14
|
+
|
|
15
|
+
## [v1.0.1](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.0.1)
|
|
16
|
+
|
|
17
|
+
- fix(typescript): fix proxyRes and router types ([#410](https://github.com/chimurai/http-proxy-middleware/issues/410)) ([dylang](https://github.com/dylang))
|
|
18
|
+
|
|
3
19
|
## [v1.0.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.0.0)
|
|
4
20
|
|
|
5
|
-
- feat(createProxyMiddleware): explicit import http-proxy-middleware (BREAKING CHANGE)([#400](https://github.com/chimurai/http-proxy-middleware/issues/400#issuecomment-587162378))
|
|
21
|
+
- 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))
|
|
6
22
|
- feat(typescript): export http-proxy-middleware types ([#400](https://github.com/chimurai/http-proxy-middleware/issues/400))
|
|
7
23
|
- fix(typescript): ES6 target - TS1192 ([#400](https://github.com/chimurai/http-proxy-middleware/issues/400#issuecomment-587064349))
|
|
8
24
|
|
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
|
|
|
@@ -228,7 +228,6 @@ Providing an alternative way to decide which requests should be proxied; In case
|
|
|
228
228
|
if (should_add_something) path += "something";
|
|
229
229
|
return path;
|
|
230
230
|
}
|
|
231
|
-
|
|
232
231
|
```
|
|
233
232
|
|
|
234
233
|
- **option.router**: object/function, re-target `option.target` for specific requests.
|
|
@@ -243,11 +242,20 @@ Providing an alternative way to decide which requests should be proxied; In case
|
|
|
243
242
|
'/rest' : 'http://localhost:8004' // path only
|
|
244
243
|
}
|
|
245
244
|
|
|
246
|
-
// Custom router function
|
|
245
|
+
// Custom router function (string target)
|
|
247
246
|
router: function(req) {
|
|
248
247
|
return 'http://localhost:8004';
|
|
249
248
|
}
|
|
250
249
|
|
|
250
|
+
// Custom router function (target object)
|
|
251
|
+
router: function(req) {
|
|
252
|
+
return {
|
|
253
|
+
protocol: 'https:', // The : is required
|
|
254
|
+
host: 'localhost',
|
|
255
|
+
port: 8004
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
|
|
251
259
|
// Asynchronous router function which returns promise
|
|
252
260
|
router: async function(req) {
|
|
253
261
|
const url = await doSomeIO();
|
|
@@ -277,7 +285,7 @@ Providing an alternative way to decide which requests should be proxied; In case
|
|
|
277
285
|
debug: logger.debug,
|
|
278
286
|
info: logger.info,
|
|
279
287
|
warn: logger.warn,
|
|
280
|
-
error: logger.error
|
|
288
|
+
error: logger.error,
|
|
281
289
|
};
|
|
282
290
|
return myCustomProvider;
|
|
283
291
|
}
|
|
@@ -292,7 +300,7 @@ Subscribe to [http-proxy events](https://github.com/nodejitsu/node-http-proxy#li
|
|
|
292
300
|
```javascript
|
|
293
301
|
function onError(err, req, res) {
|
|
294
302
|
res.writeHead(500, {
|
|
295
|
-
'Content-Type': 'text/plain'
|
|
303
|
+
'Content-Type': 'text/plain',
|
|
296
304
|
});
|
|
297
305
|
res.end('Something went wrong. And we are reporting a custom error message.');
|
|
298
306
|
}
|
|
@@ -409,7 +417,7 @@ The following options are provided by the underlying [http-proxy](https://github
|
|
|
409
417
|
res,
|
|
410
418
|
{
|
|
411
419
|
target: 'http://localhost:4003/',
|
|
412
|
-
buffer: streamify(req.rawBody)
|
|
420
|
+
buffer: streamify(req.rawBody),
|
|
413
421
|
},
|
|
414
422
|
next
|
|
415
423
|
);
|
package/dist/config-factory.js
CHANGED
|
@@ -9,7 +9,7 @@ function createConfig(context, opts) {
|
|
|
9
9
|
// structure of config object to be returned
|
|
10
10
|
const config = {
|
|
11
11
|
context: undefined,
|
|
12
|
-
options: {}
|
|
12
|
+
options: {},
|
|
13
13
|
};
|
|
14
14
|
// app.use('/api', proxy({target:'http://localhost:9000'}));
|
|
15
15
|
if (isContextless(context, opts)) {
|
|
@@ -24,8 +24,13 @@ class HttpProxyMiddleware {
|
|
|
24
24
|
// https://github.com/Microsoft/TypeScript/wiki/'this'-in-TypeScript#red-flags-for-this
|
|
25
25
|
this.middleware = (req, res, next) => __awaiter(this, void 0, void 0, function* () {
|
|
26
26
|
if (this.shouldProxy(this.config.context, req)) {
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
try {
|
|
28
|
+
const activeProxyOptions = yield this.prepareProxyRequest(req);
|
|
29
|
+
this.proxy.web(req, res, activeProxyOptions);
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
next(err);
|
|
33
|
+
}
|
|
29
34
|
}
|
|
30
35
|
else {
|
|
31
36
|
next();
|
|
@@ -35,7 +40,7 @@ class HttpProxyMiddleware {
|
|
|
35
40
|
this.catchUpgradeRequest(req.connection.server);
|
|
36
41
|
}
|
|
37
42
|
});
|
|
38
|
-
this.catchUpgradeRequest = server => {
|
|
43
|
+
this.catchUpgradeRequest = (server) => {
|
|
39
44
|
if (!this.wsInternalSubscribed) {
|
|
40
45
|
server.on('upgrade', this.handleUpgrade);
|
|
41
46
|
// prevent duplicate upgrade handling;
|
package/dist/logger.js
CHANGED
package/dist/path-rewriter.js
CHANGED
|
@@ -25,7 +25,7 @@ function createPathRewriter(rewriteConfig) {
|
|
|
25
25
|
}
|
|
26
26
|
function rewritePath(path) {
|
|
27
27
|
let result = path;
|
|
28
|
-
_.forEach(rulesCache, rule => {
|
|
28
|
+
_.forEach(rulesCache, (rule) => {
|
|
29
29
|
if (rule.regex.test(path)) {
|
|
30
30
|
result = result.replace(rule.regex, rule.value);
|
|
31
31
|
logger.debug('[HPM] Rewriting path from "%s" to "%s"', path, result);
|
|
@@ -58,7 +58,7 @@ function parsePathRewriteRules(rewriteConfig) {
|
|
|
58
58
|
_.forIn(rewriteConfig, (value, key) => {
|
|
59
59
|
rules.push({
|
|
60
60
|
regex: new RegExp(key),
|
|
61
|
-
value: rewriteConfig[key]
|
|
61
|
+
value: rewriteConfig[key],
|
|
62
62
|
});
|
|
63
63
|
logger.info('[HPM] Proxy rewrite rule created: "%s" ~> "%s"', key, rewriteConfig[key]);
|
|
64
64
|
});
|
package/dist/types.d.ts
CHANGED
|
@@ -16,12 +16,12 @@ export interface Options extends httpProxy.ServerOptions {
|
|
|
16
16
|
[regexp: string]: string;
|
|
17
17
|
} | ((path: string, req: Request) => string) | ((path: string, req: Request) => Promise<string>);
|
|
18
18
|
router?: {
|
|
19
|
-
[hostOrPath: string]:
|
|
20
|
-
} | ((req: Request) =>
|
|
19
|
+
[hostOrPath: string]: httpProxy.ServerOptions['target'];
|
|
20
|
+
} | ((req: Request) => httpProxy.ServerOptions['target']) | ((req: Request) => Promise<httpProxy.ServerOptions['target']>);
|
|
21
21
|
logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'silent';
|
|
22
22
|
logProvider?(provider: LogProvider): LogProvider;
|
|
23
23
|
onError?(err: Error, req: Request, res: Response): void;
|
|
24
|
-
onProxyRes?(proxyRes: http.
|
|
24
|
+
onProxyRes?(proxyRes: http.IncomingMessage, req: Request, res: Response): void;
|
|
25
25
|
onProxyReq?(proxyReq: http.ClientRequest, req: Request, res: Response): void;
|
|
26
26
|
onProxyReqWs?(proxyReq: http.ClientRequest, req: Request, socket: net.Socket, options: httpProxy.ServerOptions, head: any): void;
|
|
27
27
|
onOpen?(proxySocket: net.Socket): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "http-proxy-middleware",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
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,13 +15,9 @@
|
|
|
15
15
|
"lint:fix": "prettier --write \"**/*.{js,ts,md}\"",
|
|
16
16
|
"build": "tsc",
|
|
17
17
|
"pretest": "yarn build",
|
|
18
|
-
"test": "jest
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"precoveralls": "yarn clean && yarn build",
|
|
22
|
-
"coveralls": "jest --runInBand --coverage --coverageReporters=text-lcov | coveralls",
|
|
23
|
-
"postcoveralls": "yarn clean",
|
|
24
|
-
"prepare": "yarn clean && yarn build"
|
|
18
|
+
"test": "jest",
|
|
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",
|
|
@@ -50,31 +46,34 @@
|
|
|
50
46
|
},
|
|
51
47
|
"homepage": "https://github.com/chimurai/http-proxy-middleware#readme",
|
|
52
48
|
"devDependencies": {
|
|
53
|
-
"@commitlint/cli": "^8.
|
|
54
|
-
"@commitlint/config-conventional": "^8.
|
|
55
|
-
"@types/express": "^4.17.
|
|
56
|
-
"@types/is-glob": "^4.0.
|
|
57
|
-
"@types/jest": "^25.1
|
|
58
|
-
"@types/lodash": "^4.14.
|
|
49
|
+
"@commitlint/cli": "^8.3.5",
|
|
50
|
+
"@commitlint/config-conventional": "^8.3.4",
|
|
51
|
+
"@types/express": "^4.17.3",
|
|
52
|
+
"@types/is-glob": "^4.0.1",
|
|
53
|
+
"@types/jest": "^25.2.1",
|
|
54
|
+
"@types/lodash": "^4.14.150",
|
|
59
55
|
"@types/micromatch": "^4.0.1",
|
|
60
|
-
"@types/node": "^
|
|
56
|
+
"@types/node": "^13.13.5",
|
|
57
|
+
"@types/supertest": "^2.0.9",
|
|
61
58
|
"browser-sync": "^2.26.7",
|
|
62
|
-
"connect": "^3.
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
59
|
+
"connect": "^3.7.0",
|
|
60
|
+
"express": "^4.17.1",
|
|
61
|
+
"husky": "^4.2.5",
|
|
62
|
+
"jest": "^26.0.1",
|
|
63
|
+
"lint-staged": "^10.2.2",
|
|
64
|
+
"mockttp": "^0.20.1",
|
|
65
|
+
"open": "^7.0.3",
|
|
66
|
+
"prettier": "^2.0.5",
|
|
67
|
+
"supertest": "^4.0.2",
|
|
68
|
+
"ts-jest": "^25.5.0",
|
|
69
|
+
"tslint": "^6.1.2",
|
|
71
70
|
"tslint-config-prettier": "^1.18.0",
|
|
72
|
-
"typescript": "^3.
|
|
73
|
-
"ws": "^7.
|
|
71
|
+
"typescript": "^3.8.3",
|
|
72
|
+
"ws": "^7.2.5"
|
|
74
73
|
},
|
|
75
74
|
"dependencies": {
|
|
76
|
-
"@types/http-proxy": "^1.17.
|
|
77
|
-
"http-proxy": "^1.18.
|
|
75
|
+
"@types/http-proxy": "^1.17.4",
|
|
76
|
+
"http-proxy": "^1.18.1",
|
|
78
77
|
"is-glob": "^4.0.1",
|
|
79
78
|
"lodash": "^4.17.15",
|
|
80
79
|
"micromatch": "^4.0.2"
|
|
@@ -84,7 +83,8 @@
|
|
|
84
83
|
},
|
|
85
84
|
"husky": {
|
|
86
85
|
"hooks": {
|
|
87
|
-
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
|
|
86
|
+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
|
|
87
|
+
"pre-commit": "lint-staged"
|
|
88
88
|
}
|
|
89
89
|
},
|
|
90
90
|
"commitlint": {
|