Skip to content

Commit ec981c5

Browse files
committed
[fix] docs
1 parent c4ddc4e commit ec981c5

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

Diff for: README.md

+36
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,42 @@ Caronte is an HTTP programmable proxying library that supports
55
websockets. It is suitable for implementing components such as
66
proxies and load balancers.
77

8+
### Core Concept
9+
10+
A new proxy is created by calling `createProxyServer` and passing
11+
an `options` object as argument ([valid properties are available here](https://github.com/yawnt/caronte/blob/master/lib/caronte.js#L26-L39))
12+
13+
```javascript
14+
var caronte = require('caronte');
15+
16+
var proxy = caronte.createProxyServer(options);
17+
```
18+
19+
An object will be returned with four values:
20+
21+
* web `req, res, [options]` (used for proxying regular HTTP(S) requests)
22+
* ws `req, socket, head, [options]` (used for proxying WS(S) requests)
23+
* ee (an EventEmitter2 that emits events, you can hook into them to customize behaviour)
24+
* listen `port` (a function that wraps the object in a webserver, for your convenience)
25+
26+
Is it then possible to proxy requests by calling these functions
27+
28+
```javascript
29+
require('http').createServer(function(req, res) {
30+
proxy.web(req, res, { target: 'http://mytarget.com:8080' });
31+
});
32+
```
33+
34+
When a request is proxied it follows two different pipelines ([available here](https://github.com/yawnt/caronte/tree/master/lib/caronte/passes))
35+
which apply trasformations to both the `req` and `res` object.
36+
The first pipeline (ingoing) is responsible for the creation and manipulation of the stream that connects your client to the target.
37+
The second pipeline (outgoing) is responsible for the creation and manipulation of the stream that, from your target, returns datas
38+
to the client.
39+
40+
You can easily add a `pass` (stages) into both the pipelines (XXX: ADD API).
41+
42+
In addition, every stage emits a corresponding event so introspection during the process is always available.
43+
844
### Contributing and Issues
945

1046
* Search on Google/Github

0 commit comments

Comments
 (0)