Skip to content

Commit 5715318

Browse files
committed
[doc api test] Wrap things up for v0.4.0 release: Add hostnameOnly routing to ProxyTable, add more documentation, fix edge-cases until they can be further investigated in node.js core
1 parent 4110448 commit 5715318

File tree

6 files changed

+235
-105
lines changed

6 files changed

+235
-105
lines changed

README.md

+31-15
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
# node-http-proxy - v0.3.1
1+
# node-http-proxy - v0.4.0
22

33
<img src = "http://i.imgur.com/dSSUX.png"/>
44

55
## Battle-hardened node.js http proxy
66

77
### Features
88

9-
- reverse-proxies incoming http.Server requests
10-
- can be used as a CommonJS module in node.js
11-
- uses event buffering to support application latency in proxied requests
12-
- can proxy based on simple JSON-based configuration
13-
- forward proxying based on simple JSON-based configuration
14-
- minimal request overhead and latency
15-
- fully-tested
16-
- battled-hardened through production usage @ [nodejitsu.com][0]
17-
- written entirely in javascript
18-
- easy to use api
9+
* Reverse proxies incoming http.ServerRequest streams
10+
* Can be used as a CommonJS module in node.js
11+
* Uses event buffering to support application latency in proxied requests
12+
* Reverse or Forward Proxy based on simple JSON-based configuration
13+
* Minimal request overhead and latency
14+
* Full suite of functional tests
15+
* Battled-hardened through __production usage__ @ [nodejitsu.com][0]
16+
* Written entirely in Javascript
17+
* Easy to use API
1918

2019
### When to use node-http-proxy
2120

@@ -147,18 +146,34 @@ A Proxy Table is a simple lookup table that maps incoming requests to proxy targ
147146
<pre>
148147
var options = {
149148
router: {
150-
'foo.com': '127.0.0.1:8001',
151-
'bar.com': '127.0.0.1:8002'
149+
'foo.com/baz': '127.0.0.1:8001',
150+
'foo.com/buz': '127.0.0.1:8002',
151+
'bar.com/buz': '127.0.0.1:8003'
152152
}
153153
};
154154
</pre>
155155

156-
The above route table will take incoming requests to 'foo.com' and forward them to '127.0.0.1:8001'. Likewise it will take incoming requests to 'bar.com' and forward them to '127.0.0.1:8002'. The routes themselves are later converted to regular expressions to enable more complex matching functionality. We can create a proxy server with these options by using the following code:
156+
The above route table will take incoming requests to 'foo.com/baz' and forward them to '127.0.0.1:8001'. Likewise it will take incoming requests to 'foo.com/buz' and forward them to '127.0.0.1:8002'. The routes themselves are later converted to regular expressions to enable more complex matching functionality. We can create a proxy server with these options by using the following code:
157157
<pre>
158158
var proxyServer = httpProxy.createServer(options);
159159
proxyServer.listen(80);
160160
</pre>
161161

162+
### Proxy requests using a 'Hostname Only' ProxyTable
163+
As mentioned in the previous section, all routes passes to the ProxyTable are by default converted to regular expressions that are evaluated at proxy-time. This is good for complex URL rewriting of proxy requests, but less efficient when one simply wants to do pure hostname routing based on the HTTP 'Host' header. If you are only concerned with hostname routing, you change the lookup used by the internal ProxyTable:
164+
165+
<pre>
166+
var options = {
167+
hostnameOnly, true,
168+
router: {
169+
'foo.com': '127.0.0.1:8001',
170+
'bar.com': '127.0.0.1:8002'
171+
}
172+
}
173+
</pre>
174+
175+
Notice here that I have not included paths on the individual domains because this is not possible when using only the HTTP 'Host' header. Care to learn more? See [RFC2616: HTTP/1.1, Section 14.23, "Host"][1].
176+
162177
### Proxy requests with an additional forward proxy
163178
Sometimes in addition to a reverse proxy, you may want your front-facing server to forward traffic to another location. For example, if you wanted to load test your staging environment. This is possible when using node-http-proxy using similar JSON-based configuration to a proxy table:
164179
<pre>
@@ -219,4 +234,5 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
219234
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
220235
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
221236

222-
[0]: http://nodejitsu.com
237+
[0]: http://nodejitsu.com
238+
[1]: http://www.ietf.org/rfc/rfc2616.txt

0 commit comments

Comments
 (0)