Permalink
Browse files

really basic http server approach

  • Loading branch information...
1 parent cf6bdf5 commit 80059a6b3bc3fd65fe45096a4510a27b93f65c83 @substack committed Mar 19, 2013
Showing with 12 additions and 6 deletions.
  1. +12 −6 index.js
View
@@ -1,17 +1,23 @@
-var net = require('net');
+var http = require('http');
var through = require('through');
module.exports = function (cb) {
- var server = net.createServer(function (stream) {
- var src = through();
+ var server = http.createServer();
+ server.on('connection', function (stream) {
+ var src = stream._bouncySource = through();
src.pause();
stream.pipe(src);
-
+ });
+
+ server.on('request', function (req, res) {
+ var src = req.connection._bouncySource;
var bounce = function (dst) {
- src.pipe(dst).pipe(stream);
+ src.pipe(dst).pipe(req.connection);
src.resume();
};
- cb({}, bounce);
+
+ if (cb.length === 2) cb(req, bounce)
+ else cb(req, res, bounce)
});
return server;
};

0 comments on commit 80059a6

Please sign in to comment.