diff --git a/gun.js b/gun.js index 8f8f38c2..12840b9b 100644 --- a/gun.js +++ b/gun.js @@ -1,5 +1,5 @@ ;(function(){ - + //module.exports = require('../gun4');return; function Gun(o){ var gun = this; if(!Gun.is(gun)){ return new Gun(o) } @@ -816,6 +816,7 @@ return chain; } gun._.at('path:' + path[0]).event(function(at){ + if(opt.once){ this.off() } if(opt.done){ this.off(); return } // TODO: BUG - THIS IS A FIX FOR A BUG! TEST #"context no double emit", COMMENT THIS LINE OUT AND SEE IT FAIL! var ctx = {soul: at.soul, field: at.field, by: gun.__.by(at.soul)}, field = path[0]; var on = Gun.obj.as(cb.hash, at.hash, {off: function(){}}); diff --git a/lib/wsp.js b/lib/wsp.js index c9abe44b..df0b08c7 100644 --- a/lib/wsp.js +++ b/lib/wsp.js @@ -3,7 +3,7 @@ , formidable = require('formidable') , ws = require('ws').Server , http = require('./http') - , url = require('url'); + , URL = require('url'); Gun.on('opt').event(function(gun, opt){ gun.__.opt.ws = opt.ws = gun.__.opt.ws || opt.ws || {}; function start(server, port, app){ @@ -54,7 +54,7 @@ if(!req.url){ return next(), false } if(!req.method){ return next(), false } var msg = {}; - msg.url = url.parse(req.url, true); + 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'}); @@ -98,23 +98,24 @@ // all states, implemented with GET, are replied to the source that asked for it. function tran(req, cb){ req.method = req.body? 'put' : 'get'; // put or get is based on whether there is a body or not - req.url.key = req.url.pathname.replace(gun.wsp.regex,'').replace(/^\//i,'') || ''; + req.key = req.url.pathname.replace(gun.wsp.regex,'').replace(/^\//i,'') || ''; + console.log("REQUEST", req); if('get' == req.method){ return tran.get(req, cb) } if('put' == req.method || 'post' == req.method){ return tran.put(req, cb) } cb({body: {hello: 'world'}}); } tran.get = function(req, cb){ - var key = req.url.key + var key = req.key , reply = {headers: {'Content-Type': tran.json}}; //console.log(req); // NTS HACK! SHOULD BE ITS OWN ISOLATED MODULE! // - if(req && req.url && req.url.pathname && req.url.pathname.indexOf('gun.nts') >= 0){ + if(req.url && req.url.pathname && req.url.pathname.indexOf('gun.nts') >= 0){ return cb({headers: reply.headers, body: {time: Gun.time.is() }}); } // NTS END! SHOULD HAVE BEEN ITS OWN MODULE // // ALL HACK! SHOULD BE ITS OWN MODULE OR CORE? // - if(req && req.url && Gun.obj.has(req.url.query, '*')){ - return gun.all(req.url.key + req.url.search, function(err, list){ + if(req.url && Gun.obj.has(req.url.query, '*')){ + return gun.all(req.key + req.url.search, function(err, list){ cb({headers: reply.headers, body: (err? (err.err? err : {err: err || "Unknown error."}) : list || null ) }) }); }