Permalink
Browse files

added option for node/listen to work on existing servers.

  • Loading branch information...
1 parent 206c223 commit 70cbcd47d81bbd856e65370e6d00f513795e2fa6 @jed committed Oct 4, 2010
Showing with 8 additions and 4 deletions.
  1. +8 −4 node/listen.js
View
@@ -1,11 +1,15 @@
module.exports = function( exports, imports ) {
+ var http = require( "http" );
+
return imports( function( stream, listener ) {
- return exports( function( write, port ) {
+ return exports( function( write, server ) {
+ if ( !( server instanceof http.Server ) ) {
+ server = http.createServer().listen( server );
+ }
+
return stream( function( upstream ) {
upstream( listener( function( listener ) {
- require( "http" )
- .createServer( listener )
- .listen( port );
+ server.on( "request", listener );
}))
return upstream( write );

0 comments on commit 70cbcd4

Please sign in to comment.