mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
[doc] update README.md
This commit is contained in:
parent
54eceb4a86
commit
dcb873ad99
18
README.md
18
README.md
@ -33,7 +33,6 @@ An object will be returned with four values:
|
|||||||
|
|
||||||
* web `req, res, [options]` (used for proxying regular HTTP(S) requests)
|
* web `req, res, [options]` (used for proxying regular HTTP(S) requests)
|
||||||
* ws `req, socket, head, [options]` (used for proxying WS(S) requests)
|
* ws `req, socket, head, [options]` (used for proxying WS(S) requests)
|
||||||
* ee (an EventEmitter2 that emits events, you can hook into them to customize behaviour)
|
|
||||||
* listen `port` (a function that wraps the object in a webserver, for your convenience)
|
* listen `port` (a function that wraps the object in a webserver, for your convenience)
|
||||||
|
|
||||||
Is it then possible to proxy requests by calling these functions
|
Is it then possible to proxy requests by calling these functions
|
||||||
@ -44,15 +43,26 @@ require('http').createServer(function(req, res) {
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Errors can be listened on either using the Event Emitter API
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
proxy.on('error', function(e) {
|
||||||
|
...
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
or using the callback API
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
proxy.web(req, res, { target: 'http://mytarget.com:8080' }, function(e) { ... });
|
||||||
|
```
|
||||||
|
|
||||||
When a request is proxied it follows two different pipelines ([available here](lib/http-proxy/passes))
|
When a request is proxied it follows two different pipelines ([available here](lib/http-proxy/passes))
|
||||||
which apply transformations to both the `req` and `res` object.
|
which apply transformations to both the `req` and `res` object.
|
||||||
The first pipeline (ingoing) is responsible for the creation and manipulation of the stream that connects your client to the target.
|
The first pipeline (ingoing) is responsible for the creation and manipulation of the stream that connects your client to the target.
|
||||||
The second pipeline (outgoing) is responsible for the creation and manipulation of the stream that, from your target, returns data
|
The second pipeline (outgoing) is responsible for the creation and manipulation of the stream that, from your target, returns data
|
||||||
to the client.
|
to the client.
|
||||||
|
|
||||||
You can easily add a `pass` (stages) into both the pipelines (XXX: ADD API).
|
|
||||||
|
|
||||||
In addition, every stage emits a corresponding event so introspection during the process is always available.
|
|
||||||
|
|
||||||
#### Setup a basic stand-alone proxy server
|
#### Setup a basic stand-alone proxy server
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user