From c1d3637bbb7df5b675f46485a728c02f007d886a Mon Sep 17 00:00:00 2001 From: Koen Kooi Date: Mon, 5 Dec 2011 14:16:44 +0100 Subject: [PATCH 1/2] bonescript: add ipv6 version for bb.Server Signed-off-by: Koen Kooi --- bonescript/index.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/bonescript/index.js b/bonescript/index.js index 640cb7cb..f8ecd79a 100644 --- a/bonescript/index.js +++ b/bonescript/index.js @@ -350,3 +350,34 @@ exports.Server = function(port, subdir) { this.server.listen(port); }; }; + +exports.Server6 = function(port, subdir, onconnect) { + subdir = path.join(process.cwd(), subdir); + this.server = http.createServer( + function(req, res) { + var uri = url.parse(req.url).pathname; + if(uri == '/') { + loadFile('index.html', subdir, res, "text/html"); + } else { + if(uri.match(/\.js$/i)) { + loadFile(uri, subdir, res, "application/javascript"); + } else if(uri.match(/\.css$/i)) { + loadFile(uri, subdir, res, "text/css"); + } else if(uri.match(/\.htm(.)$/i)) { + loadFile(uri, subdir, res, "text/html"); + } else if(uri.match(/\.(jpg|png|ico)$/i)) { + loadFile(uri, subdir, res, "binary"); + } else { + loadFile(uri, subdir, res, "text/plain"); + } + } + } + ); + if(socket.exists && (typeof onconnect == 'function')) { + var io = socket.listen(this.server); + io.sockets.on('connection', onconnect); + } + this.begin = function() { + this.server.listen(port, '::0'); + }; +}; From ac7afa0c7fb975e1d98f6ff28d4a613b2e35ac4b Mon Sep 17 00:00:00 2001 From: Koen Kooi Date: Tue, 27 Dec 2011 16:58:00 +0100 Subject: [PATCH 2/2] bonescript: fixup ipv4 on_connect to not error out if the socket is occupied already by the ipv6 server Signed-off-by: Koen Kooi --- bonescript/index.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bonescript/index.js b/bonescript/index.js index f8ecd79a..f5c0bdaf 100644 --- a/bonescript/index.js +++ b/bonescript/index.js @@ -324,7 +324,7 @@ var loadFile = function(uri, subdir, res, type) { ); }; -exports.Server = function(port, subdir) { +exports.Server = function(port, subdir, onconnect) { subdir = path.join(process.cwd(), subdir); this.server = http.createServer( function(req, res) { @@ -344,8 +344,12 @@ exports.Server = function(port, subdir) { loadFile(uri, subdir, res, "text/plain"); } } - } + } ); + if(socket.exists && (typeof onconnect == 'function')) { + var io = socket.listen(this.server); + io.sockets.on('connection', onconnect); + } this.begin = function() { this.server.listen(port); }; @@ -380,4 +384,4 @@ exports.Server6 = function(port, subdir, onconnect) { this.begin = function() { this.server.listen(port, '::0'); }; -}; +}; \ No newline at end of file