diff --git a/lib/wsp.js b/lib/wsp.js index 09ea2a02..7768fa86 100644 --- a/lib/wsp.js +++ b/lib/wsp.js @@ -34,7 +34,7 @@ if(msg && msg.headers){ delete msg.headers['ws-rid'] } // TODO: BUG? ^ What if other peers want to ack? Do they use the ws-rid or a gun declared id? try{ws.send(Gun.text.ify(msg)); - }catch(e){} // juuuust in case. + }catch(e){} // juuuust in case. }); gun.wsp.wire(req, res); }, {headers: {'ws-rid': 1, 'gun-sid': 1}}); @@ -67,18 +67,18 @@ gun.wsp.server = gun.wsp.server || function(req, res, next){ // http next = next || function(){}; if(!req || !res){ return next(), false } - if(!req.upgrade){ return next(), false } - if(!req.url){ return next(), false } - if(!req.method){ return next(), false } - var msg = {}; - msg.url = url.parse(req.url, true); - if(!gun.wsp.regex.test(msg.url.pathname)){ return next(), false } // TODO: BUG! If the option isn't a regex then this will fail! - if(msg.url.pathname.replace(gun.wsp.regex,'').slice(0,3).toLowerCase() === '.js'){ - res.writeHead(200, {'Content-Type': 'text/javascript'}); - res.end(gun.wsp.js = gun.wsp.js || require('fs').readFileSync(__dirname + '/../gun.js')); // gun server is caching the gun library for the client - return true; - } - return http(req, res, function(req, res){ + if(!req.url){ return next(), false } + if(!req.method){ return next(), false } + var msg = {}; + msg.url = url.parse(req.url, true); + if(!gun.wsp.regex.test(msg.url.pathname)){ return next(), false } // TODO: BUG! If the option isn't a regex then this will fail! + if(msg.url.pathname.replace(gun.wsp.regex,'').slice(0,3).toLowerCase() === '.js'){ + res.writeHead(200, {'Content-Type': 'text/javascript'}); + res.end(gun.wsp.js = gun.wsp.js || require('fs').readFileSync(__dirname + '/../gun.js')); // gun server is caching the gun library for the client + return true; + } + if(!req.upgrade){ return next(), false } + return http(req, res, function(req, res){ if(!req){ return next() } var stream, cb = res = require('./jsonp')(req, res); if(req.headers && (stream = req.headers['gun-sid'])){ @@ -121,7 +121,7 @@ Gun.obj.del(gun.wsp.msg.debounce, id); }); },500); - if(id = gun.wsp.msg.debounce[id]){ + if(id = gun.wsp.msg.debounce[id]){ return gun.wsp.msg.debounce[id] = Gun.time.is(), id; } gun.wsp.msg.debounce[id] = Gun.time.is();