index.js 550 B

1234567891011121314151617181920212223242526
  1. var fs = require('fs'),
  2. path = require('path'),
  3. union = require('../../lib');
  4. var server = union.createServer({
  5. before: [ function (req,res) {
  6. if (req.url === "/foo") {
  7. res.text(201, "foo");
  8. }
  9. } ],
  10. after: [
  11. function LoggerStream() {
  12. var stream = new union.ResponseStream();
  13. stream.once("pipe", function (req) {
  14. console.log({res: this.res.statusCode, method: this.req.method});
  15. });
  16. return stream;
  17. }
  18. ]
  19. });
  20. server.listen(9080);
  21. console.log('union running on 9080');