mirror of
https://github.com/amark/gun.git
synced 2025-07-04 11:52:34 +00:00
switch to real work
This commit is contained in:
parent
c03b7d4e1e
commit
a1bc9a27f2
3
gun.js
3
gun.js
@ -1,5 +1,5 @@
|
|||||||
;(function(){
|
;(function(){
|
||||||
|
//module.exports = require('../gun4');return;
|
||||||
function Gun(o){
|
function Gun(o){
|
||||||
var gun = this;
|
var gun = this;
|
||||||
if(!Gun.is(gun)){ return new Gun(o) }
|
if(!Gun.is(gun)){ return new Gun(o) }
|
||||||
@ -816,6 +816,7 @@
|
|||||||
return chain;
|
return chain;
|
||||||
}
|
}
|
||||||
gun._.at('path:' + path[0]).event(function(at){
|
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!
|
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 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(){}});
|
var on = Gun.obj.as(cb.hash, at.hash, {off: function(){}});
|
||||||
|
15
lib/wsp.js
15
lib/wsp.js
@ -3,7 +3,7 @@
|
|||||||
, formidable = require('formidable')
|
, formidable = require('formidable')
|
||||||
, ws = require('ws').Server
|
, ws = require('ws').Server
|
||||||
, http = require('./http')
|
, http = require('./http')
|
||||||
, url = require('url');
|
, URL = require('url');
|
||||||
Gun.on('opt').event(function(gun, opt){
|
Gun.on('opt').event(function(gun, opt){
|
||||||
gun.__.opt.ws = opt.ws = gun.__.opt.ws || opt.ws || {};
|
gun.__.opt.ws = opt.ws = gun.__.opt.ws || opt.ws || {};
|
||||||
function start(server, port, app){
|
function start(server, port, app){
|
||||||
@ -54,7 +54,7 @@
|
|||||||
if(!req.url){ return next(), false }
|
if(!req.url){ return next(), false }
|
||||||
if(!req.method){ return next(), false }
|
if(!req.method){ return next(), false }
|
||||||
var msg = {};
|
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(!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'){
|
if(msg.url.pathname.replace(gun.wsp.regex,'').slice(0,3).toLowerCase() === '.js'){
|
||||||
res.writeHead(200, {'Content-Type': 'text/javascript'});
|
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.
|
// all states, implemented with GET, are replied to the source that asked for it.
|
||||||
function tran(req, cb){
|
function tran(req, cb){
|
||||||
req.method = req.body? 'put' : 'get'; // put or get is based on whether there is a body or not
|
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('get' == req.method){ return tran.get(req, cb) }
|
||||||
if('put' == req.method || 'post' == req.method){ return tran.put(req, cb) }
|
if('put' == req.method || 'post' == req.method){ return tran.put(req, cb) }
|
||||||
cb({body: {hello: 'world'}});
|
cb({body: {hello: 'world'}});
|
||||||
}
|
}
|
||||||
tran.get = function(req, cb){
|
tran.get = function(req, cb){
|
||||||
var key = req.url.key
|
var key = req.key
|
||||||
, reply = {headers: {'Content-Type': tran.json}};
|
, reply = {headers: {'Content-Type': tran.json}};
|
||||||
//console.log(req);
|
//console.log(req);
|
||||||
// NTS HACK! SHOULD BE ITS OWN ISOLATED MODULE! //
|
// 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() }});
|
return cb({headers: reply.headers, body: {time: Gun.time.is() }});
|
||||||
}
|
}
|
||||||
// NTS END! SHOULD HAVE BEEN ITS OWN MODULE //
|
// NTS END! SHOULD HAVE BEEN ITS OWN MODULE //
|
||||||
// ALL HACK! SHOULD BE ITS OWN MODULE OR CORE? //
|
// ALL HACK! SHOULD BE ITS OWN MODULE OR CORE? //
|
||||||
if(req && req.url && Gun.obj.has(req.url.query, '*')){
|
if(req.url && Gun.obj.has(req.url.query, '*')){
|
||||||
return gun.all(req.url.key + req.url.search, function(err, list){
|
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 ) })
|
cb({headers: reply.headers, body: (err? (err.err? err : {err: err || "Unknown error."}) : list || null ) })
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user