flatiron/union — Issue #8: Odd issues with response stream missing a bunch of stuff
Author: jesusabdullah
Created: 2011-11-21 19:01:39+00:00
State: open

So, I've been trying to get a static middleware for union (and express) running, and I got a bunch of nice features implemented by @substack but getting it to work with union is being painful.

Running the example with the gh-4 branch (which tries to implement getHeader & friends) and trying to get `/hello.txt` gets you this:

```bash
josh@onix:~/dev/ecstatic$ node example/union.js
Listening on :8080

/home/josh/dev/union/lib/http-stream.js:40
this.query = ~source.url.indexOf('?')
^
TypeError: Cannot call method 'indexOf' of undefined
at [object Object].pipeState (/home/josh/dev/union/lib/http-stream.js:40:30)
at [object Object].emit (events.js:81:20)
at [object Object].pipe (stream.js:159:8)
at /home/josh/dev/ecstatic/ecstatic.js:52:11
[1]+ Done gedit ecstatic.js
josh@onix:~/dev/ecstatic$
```
So, source.url is missing. Okay, I can circumvent this. But, when I do, it seems the problem's deeper:

```bash
josh@onix:~/dev/ecstatic$ node example/union.js
Listening on :8080
Cannot call method 'indexOf' of undefined

events.js:143
listener.apply(this, arguments);
^
TypeError: Cannot call method 'apply' of undefined
at [object Object].g (events.js:143:14)
at [object Object].emit (events.js:81:20)
at [object Object].pipe (stream.js:159:8)
at /home/josh/dev/ecstatic/ecstatic.js:52:11
josh@onix:~/dev/ecstatic$
```

This is what ecstatic is doing with the response around that time:

```js
res.setHeader('content-type', mime.lookup(file));
var s = fs.createReadStream(file);
s.pipe(res);
s.on('error', function (err) {
res.statusCode = 500;
if (res.writable) res.end(err && err.stack || err.toString());
});
```

and the error seems to occur on s.pipe(res).

I'd fix this myself but I'm not really sure where to look.