From dcb873ad9992b1534615d59b8a0a70e8b87d7884 Mon Sep 17 00:00:00 2001 From: yawnt Date: Wed, 13 Nov 2013 18:29:15 +0100 Subject: [PATCH] [doc] update README.md --- README.md | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 344d6c3..904b779 100644 --- a/README.md +++ b/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) * 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