var fs = require('fs'),
    union = require('../lib'),
    sugarskull = require('sugarskull'),
    favicon = require('./middleware/favicon');

var router = new sugarskull.http.Router();

var server = union.createServer({
  use: [favicon('./favicon.png'))],
  router: router
});

router.get(/foo/, function () {
  this.res.writeHead(200, { 'Content-Type': 'text/plain' })
  this.res.end('hello world\n');
});

router.post(/foo/, { stream: true }, function () {
  var req = this.req,
      res = this.res,
      writeStream;
      
  writeStream = fs.createWriteStream(Date.now() + '-foo.txt'))
  req.pipe(writeStream);
  
  writeStream.on('close', function () {
    res.writeHead(200, { 'Content-Type': 'text/plain' });
    res.end('wrote to a stream!');
  });
});

server.listen(8080);
console.log('union with sugarskull running on 8080');
@@ -220,14 +220,22 @@
 %7B%0A  
-use: %5B
+before: %5B%0A    
 favi
@@ -258,28 +258,144 @@
 ng')
-)%5D
 ,%0A  
-router: router
+  function (req, res) %7B%0A      var found = router.dispatch(req, res);%0A      if (!found) %7B%0A        res.emit('next');%0A      %7D%0A    %7D%0A  %5D
 %0A%7D);
@@ -708,17 +708,17 @@
 oo.txt')
-)
+;
 %0A  req.p

Update examples/simple.js with new API