nodejitsu/node-http-proxy — Issue #199: Order of hostname routes cause folder routes to fail
Author: locksmithdon
Created: 2012-02-19 03:27:17+00:00
State: open

If you define both a hostname route along with folder routes on the same hostname, the hostname route MUST be defined after all of its folder routes or any folder routes defined after the hostname route will return a "Cannot GET /folder".

To repro, in `test/http/routing-proxy-test.js`, add a baz.com route to `defaultOptions`:

```javascript
var defaultOptions = {
router: {
"foo.com": "127.0.0.1:8091",
"bar.com": "127.0.0.1:8092",
"baz.com": "127.0.0.1:8096", // will cause the /taco assertion to fail
"baz.com/taco": "127.0.0.1:8098",
"pizza.com/taco/muffins": "127.0.0.1:8099",
}
};
```

If you move baz.com after baz.com/taco, the test will pass.

I suspect the test runner (`assertProxied` method) will need fixing too. Because this repro will fail with an "address in use" error even though the ports are unique.

```
$ vows test/http/*-test.js
········ ···········
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: listen EADDRINUSE
at errnoException (net.js:642:11)
at Array.0 (net.js:743:26)
at EventEmitter._tickCallback (node.js:192:40)
```

Even when I added a specific assertion for baz.com

``` javascript
"an incoming request to baz.com": runner.assertProxied('baz.com', 8090, 8096),
```
the expectations still aren't correct even though the correct test is failing (baz.com/taco).

```
$ vows test/http/*-test.js
········ ·······✗·········
When using server created by httpProxy.createServer() when passed a
routing table and routing by RegExp an incoming request to baz.com/taco
✗ should receive 'hello baz.com/'
» expected 'hello baz.com/',
got	'hello baz.com' (==) // helpers.js:95
✗ Broken » 24 honored ∙ 1 broken (6.152s)
```

I'll send a pull request if I get a chance.