http-proxy-middleware 1.2.0-beta.2 → 1.2.0

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 CHANGED
@@ -1,8 +1,13 @@
1
1
  # Changelog
2
2
 
3
- ## next
3
+ ## [v1.2.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.2.0)
4
4
 
5
- - feat(handler): response interceptor
5
+ - feat(handler): response interceptor ([#520](https://github.com/chimurai/http-proxy-middleware/pull/520))
6
+ - fix(log error): handle undefined target when websocket errors ([#527](https://github.com/chimurai/http-proxy-middleware/pull/527))
7
+
8
+ ## [v1.1.2](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.1.2)
9
+
10
+ - fix(log error): handle optional target ([#523](https://github.com/chimurai/http-proxy-middleware/pull/523))
6
11
 
7
12
  ## [v1.1.1](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.1.1)
8
13
 
package/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # http-proxy-middleware
2
2
 
3
- [![Build Status](https://img.shields.io/travis/chimurai/http-proxy-middleware/master.svg?style=flat-square)](https://travis-ci.org/chimurai/http-proxy-middleware)
3
+ [![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/chimurai/http-proxy-middleware/Test/master?style=flat-square)](https://github.com/chimurai/http-proxy-middleware/actions?query=branch%3Amaster)
4
4
  [![Coveralls](https://img.shields.io/coveralls/chimurai/http-proxy-middleware.svg?style=flat-square)](https://coveralls.io/r/chimurai/http-proxy-middleware)
5
5
  [![dependency Status](https://img.shields.io/david/chimurai/http-proxy-middleware.svg?style=flat-square)](https://david-dm.org/chimurai/http-proxy-middleware#info=dependencies)
6
6
  [![dependency Status](https://snyk.io/test/npm/http-proxy-middleware/badge.svg?style=flat-square)](https://snyk.io/test/npm/http-proxy-middleware)
7
- [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
7
+ [![npm](https://img.shields.io/npm/v/http-proxy-middleware?color=%23CC3534&style=flat-square)](https://www.npmjs.com/package/http-proxy-middleware)
8
8
 
9
9
  Node.js proxying made simple. Configure proxy middleware with ease for [connect](https://github.com/senchalabs/connect), [express](https://github.com/strongloop/express), [browser-sync](https://github.com/BrowserSync/browser-sync) and [many more](#compatible-servers).
10
10
 
@@ -299,7 +299,7 @@ Subscribe to [http-proxy events](https://github.com/nodejitsu/node-http-proxy#li
299
299
  - **option.onError**: function, subscribe to http-proxy's `error` event for custom error handling.
300
300
 
301
301
  ```javascript
302
- function onError(err, req, res) {
302
+ function onError(err, req, res, target) {
303
303
  res.writeHead(500, {
304
304
  'Content-Type': 'text/plain',
305
305
  });
@@ -488,7 +488,7 @@ Intercept responses from upstream with `responseInterceptor`. (Make sure to set
488
488
 
489
489
  Responses which are compressed with `brotli`, `gzip` and `deflate` will be decompressed automatically. The response will be returned as `buffer` ([docs](https://nodejs.org/api/buffer.html)) which you can manipulate.
490
490
 
491
- With `buffer`, response manipulation is not limited to text responses (html/css/js, etc...); image manipulation will be possible too. ([example](https://github.com/chimurai/http-proxy-middleware/blob/master/response-interceptor/recipes/response-interceptor.md#manipulate-image-response))
491
+ With `buffer`, response manipulation is not limited to text responses (html/css/js, etc...); image manipulation will be possible too. ([example](https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/response-interceptor.md#manipulate-image-response))
492
492
 
493
493
  NOTE: `responseInterceptor` disables streaming of target's response.
494
494
 
@@ -513,7 +513,7 @@ const proxy = createProxyMiddleware({
513
513
  });
514
514
  ```
515
515
 
516
- Check out [interception recipes](https://github.com/chimurai/http-proxy-middleware/blob/master/response-interceptor/recipes/response-interceptor.md#readme) for more examples.
516
+ Check out [interception recipes](https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/response-interceptor.md#readme) for more examples.
517
517
 
518
518
  ## Working examples
519
519
 
@@ -523,7 +523,7 @@ View and play around with [working examples](https://github.com/chimurai/http-pr
523
523
  - express ([example source](https://github.com/chimurai/http-proxy-middleware/tree/master/examples/express/index.js))
524
524
  - connect ([example source](https://github.com/chimurai/http-proxy-middleware/tree/master/examples/connect/index.js))
525
525
  - WebSocket ([example source](https://github.com/chimurai/http-proxy-middleware/tree/master/examples/websocket/index.js))
526
- - Response Manipulation ([example source](https://github.com/chimurai/http-proxy-middleware/blob/master/response-interceptor/examples/response-interceptor/index.js))
526
+ - Response Manipulation ([example source](https://github.com/chimurai/http-proxy-middleware/blob/master/examples/response-interceptor/index.js))
527
527
 
528
528
  ## Recipes
529
529
 
@@ -22,7 +22,7 @@ function responseInterceptor(interceptor) {
22
22
  return function proxyRes(proxyRes, req, res) {
23
23
  return __awaiter(this, void 0, void 0, function* () {
24
24
  const originalProxyRes = proxyRes;
25
- let buffer = Buffer.from('', 'utf-8');
25
+ let buffer = Buffer.from('', 'utf8');
26
26
  // decompress proxy response
27
27
  const _proxyRes = decompress(proxyRes, proxyRes.headers['content-encoding']);
28
28
  // concat data stream
@@ -33,7 +33,7 @@ function responseInterceptor(interceptor) {
33
33
  // call interceptor with intercepted response (buffer)
34
34
  const interceptedBuffer = Buffer.from(yield interceptor(buffer, originalProxyRes, req, res));
35
35
  // set correct content-length (with double byte character support)
36
- res.setHeader('content-length', Buffer.byteLength(interceptedBuffer, 'utf-8'));
36
+ res.setHeader('content-length', Buffer.byteLength(interceptedBuffer, 'utf8'));
37
37
  res.write(interceptedBuffer);
38
38
  res.end();
39
39
  }));
@@ -135,12 +135,14 @@ class HttpProxyMiddleware {
135
135
  }
136
136
  }
137
137
  });
138
- this.logError = (err, req, res) => {
139
- const hostname = (req.headers && req.headers.host) || req.hostname || req.host; // (websocket) || (node0.10 || node 4/5)
140
- const target = this.proxyOptions.target.host || this.proxyOptions.target;
141
- const errorMessage = '[HPM] Error occurred while trying to proxy request %s from %s to %s (%s) (%s)';
138
+ this.logError = (err, req, res, target) => {
139
+ var _a;
140
+ const hostname = ((_a = req.headers) === null || _a === void 0 ? void 0 : _a.host) || req.hostname || req.host; // (websocket) || (node0.10 || node 4/5)
141
+ const requestHref = `${hostname}${req.url}`;
142
+ const targetHref = `${target === null || target === void 0 ? void 0 : target.href}`; // target is undefined when websocket errors
143
+ const errorMessage = '[HPM] Error occurred while proxying request %s to %s [%s] (%s)';
142
144
  const errReference = 'https://nodejs.org/api/errors.html#errors_common_system_errors'; // link to Node Common Systems Errors page
143
- this.logger.error(errorMessage, req.url, hostname, target, err.code || err, errReference);
145
+ this.logger.error(errorMessage, requestHref, targetHref, err.code || err, errReference);
144
146
  };
145
147
  this.config = config_factory_1.createConfig(context, opts);
146
148
  this.proxyOptions = this.config.options;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "http-proxy-middleware",
3
- "version": "1.2.0-beta.2",
3
+ "version": "1.2.0",
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",