[doc] update README.md

This commit is contained in:
yawnt 2013-11-13 18:29:15 +01:00
parent 54eceb4a86
commit dcb873ad99

View File

@ -33,7 +33,6 @@ An object will be returned with four values:
* web `req, res, [options]` (used for proxying regular HTTP(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)
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))
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 second pipeline (outgoing) is responsible for the creation and manipulation of the stream that, from your target, returns data
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