Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 120 lines (80 sloc) 2.531 kb
0a8d54e @substack initial thing, seems to work
authored
1 bouncy
2 ======
3
4 Bouncy uses node's http parser innards to bounce http requests around to where
96c27c8 @substack note about transparency
authored
5 they need to go in an entirely transparent way.
0a8d54e @substack initial thing, seems to work
authored
6
122eb00 @substack notes about bouncy the command
authored
7 Use bouncy as a load balancer or http host router, either programmatically or
8 with the simple command-line tool.
0a8d54e @substack initial thing, seems to work
authored
9
e9fb43a @substack bump to 0.0.2 for websocket-capable
authored
10 Bouncy is websocket-capable.
11
f58313d @substack silly github, why you gotta emailify my semvers?
authored
12 Bouncy 0.0.4 is [faster than http-proxy 0.7.3](https://gist.github.com/1275259) in
793c24e @substack fix a broken link
authored
13 [this benchmark](https://github.com/substack/bouncy/tree/master/bench).
3b009d8 @substack link to the benchmark
authored
14
0a8d54e @substack initial thing, seems to work
authored
15 example
16 =======
17
ff8c99e @substack route example
authored
18 route.js
19 --------
20
21 Route requests based on the host field
22
23 ````javascript
24 var bouncy = require('bouncy');
25
26 bouncy(function (req, bounce) {
27 if (req.headers.host === 'beep.example.com') {
28 bounce(8001);
29 }
ef9db01 @substack fixed a typo in the route example
authored
30 else if (req.headers.host === 'boop.example.com') {
ff8c99e @substack route example
authored
31 bounce(8002)
32 }
33 }).listen(8000);
34 ````
35
122eb00 @substack notes about bouncy the command
authored
36 command-line
37 ============
0a8d54e @substack initial thing, seems to work
authored
38
122eb00 @substack notes about bouncy the command
authored
39 Just create a `routes.json` file like this:
0a8d54e @substack initial thing, seems to work
authored
40
41 ````javascript
122eb00 @substack notes about bouncy the command
authored
42 {
43 "beep.example.com" : 8000,
44 "boop.example.com" : 8001
45 }
0a8d54e @substack initial thing, seems to work
authored
46 ````
47
122eb00 @substack notes about bouncy the command
authored
48 Then point the `bouncy` command at this `routes.json` file and give it a port to
49 listen on:
50
51 bouncy routes.json 80
52
53 The `routes.json` file should just map host names to host/port combos.
54 Use a colon-separated string to specify a host and port in a route.
55 Use `''` as a default route.
56
92d290b @substack s/methods/bouncy(cb)/
authored
57 bouncy(cb)
58 ==========
fe380a5 @substack documented the sugar and a bump to 0.0.1
authored
59
aec7719 @substack notes about bounce.respond()
authored
60 `bouncy(cb)` returns a new net.Server object that you can `.listen()` on.
61
62 Your callback `cb` will get these arguments:
fe380a5 @substack documented the sugar and a bump to 0.0.1
authored
63
64 req
65 ---
66
67 The node http module request object.
68
024af40 @substack drop addHeader in favor of opts.headers
authored
69 bounce(stream, opts={})
70 -----------------------
fe380a5 @substack documented the sugar and a bump to 0.0.1
authored
71
72 Call this function when you're ready to bounce the request to a stream.
73
74 The exact request that was received will be written to `stream` and future
75 incoming data will be piped to and from it.
76
024af40 @substack drop addHeader in favor of opts.headers
authored
77 You can specify header fields to insert into the request with `opts.headers`.
78
79 For instance you might want to add an `"x-forwarded-for"` header:
80
81 ```javascript
82 var bouncy = require('bouncy');
83
84 bouncy(function (req, bounce) {
85 bounce(5000, { headers : 'x-forwarded-for' : req.socket.remoteAddress });
86 }).listen(80);
87 ````
88
89 bounce(port, ...), bounce(host, port, ...)
90 ------------------------------------------
fe380a5 @substack documented the sugar and a bump to 0.0.1
authored
91
92 These variants of `bounce()` are sugar for
93 `bounce(net.createConnection(port))`
94 and
95 `bounce(net.createConnection(port, host))`.
96
024af40 @substack drop addHeader in favor of opts.headers
authored
97 bounce.respond()
98 ----------------
aec7719 @substack notes about bounce.respond()
authored
99
100 Return a new HTTP response object for the request.
101 This is useful if you need to write an error result.
102
0a8d54e @substack initial thing, seems to work
authored
103 install
104 =======
105
106 With [npm](http://npmjs.org), do:
107
108 npm install bouncy
109
122eb00 @substack notes about bouncy the command
authored
110 to install as a library or
111
112 npm install -g bouncy
113
114 to get the command-line tool.
115
0a8d54e @substack initial thing, seems to work
authored
116 license
117 =======
118
119 MIT/X11
Something went wrong with that request. Please try again.