You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+26
Original file line number
Diff line number
Diff line change
@@ -377,6 +377,7 @@ proxyServer.listen(8015);
377
377
* **timeout**: timeout (in millis) for incoming requests
378
378
* **followRedirects**: true/false, Default: false - specify whether you want to follow redirects
379
379
* **selfHandleRequest** true/false, if set to true, none of the webOutgoing passes are called and its your responsibility ro appropriately return the response by listening and acting on the `proxyRes` event
380
+
* **modifyResponse**: do not pipe proxyRes to res, so you can respond to client with your own response. It still goes through all out going web passes unlike selfHandleRequest
380
381
* **buffer**: stream of data to send as the request body. Maybe you have some middleware that consumes the request stream before proxying it on e.g. If you read the body of a request into a field called 'req.rawbody' you could restream this field in the buffer option:
381
382
382
383
```
@@ -395,6 +396,7 @@ proxyServer.listen(8015);
395
396
396
397
};
397
398
```
399
+
398
400
**NOTE:**
399
401
`options.ws` and `options.ssl` are optional.
400
402
`options.target` and `options.forward` cannot both be missing
@@ -485,6 +487,30 @@ proxy.close();
485
487
486
488
### Miscellaneous
487
489
490
+
### Modify response
491
+
492
+
```
493
+
494
+
var option = {
495
+
target: target,
496
+
modifyResponse : true
497
+
};
498
+
proxy.on('proxyRes', function (proxyRes, req, res) {
499
+
var body = new Buffer('');
500
+
proxyRes.on('data', function (data) {
501
+
body = Buffer.concat([body, data]);
502
+
});
503
+
proxyRes.on('end', function () {
504
+
body = body.toString();
505
+
console.log("res from proxied server:", body);
506
+
res.end("my response to cli");
507
+
});
508
+
});
509
+
proxy.web(req, res, option);
510
+
511
+
512
+
```
513
+
488
514
#### ProxyTable API
489
515
490
516
A proxy table API is available through this add-on [module](https://github.com/donasaur/http-proxy-rules), which lets you define a set of rules to translate matching routes to target routes that the reverse proxy will talk to.
0 commit comments