mirror of
https://github.com/amark/gun.git
synced 2025-03-30 15:08:33 +00:00
remove deps, http now default, version bump
This commit is contained in:
parent
5b2c0477a1
commit
9bef479823
@ -17,4 +17,4 @@ var gun = Gun({
|
||||
gun.attach(app);
|
||||
app.use(express.static(__dirname)).listen(port);
|
||||
|
||||
console.log('Server started on port ' + port + ' with /gun');
|
||||
console.log('Server started on port ' + port + ' with /gun');
|
@ -1,7 +1,5 @@
|
||||
var port = process.env.OPENSHIFT_NODEJS_PORT || process.env.VCAP_APP_PORT || process.env.PORT || process.argv[2] || 80;
|
||||
|
||||
var http = require('http');
|
||||
|
||||
var Gun = require('gun');
|
||||
var gun = Gun({
|
||||
file: 'data.json',
|
||||
@ -12,10 +10,16 @@ var gun = Gun({
|
||||
}
|
||||
});
|
||||
|
||||
var server = http.createServer(function(req, res){
|
||||
gun.server(req, res);
|
||||
var server = require('http').createServer(function(req, res){
|
||||
if(gun.server(req, res)){
|
||||
return; // filters gun requests!
|
||||
}
|
||||
require('fs').createReadStream(require('path').join(__dirname, req.url)).on('error',function(){ // static files!
|
||||
res.writeHead(200, {'Content-Type': 'text/html'});
|
||||
res.end(require('fs').readFileSync(require('path').join(__dirname, 'index.html'))); // or default to index
|
||||
}).pipe(res); // stream
|
||||
});
|
||||
gun.attach(server);
|
||||
server.listen(port);
|
||||
|
||||
console.log('Server started on port ' + port + ' with /gun');
|
||||
console.log('Server started on port ' + port + ' with /gun');
|
17
gun.js
17
gun.js
@ -12,7 +12,7 @@
|
||||
,HAM: '>'
|
||||
}
|
||||
;(function(Gun){ // GUN specific utilities
|
||||
Gun.version = 0.1; // TODO: When Mark (or somebody) does a push/publish, dynamically update package.json
|
||||
Gun.version = 0.2; // TODO: When Mark (or somebody) does a push/publish, dynamically update package.json
|
||||
Gun.is = function(gun){ return (gun instanceof Gun)? true : false }
|
||||
Gun.is.value = function(v){ // null, binary, number (!Infinity), text, or a rel (soul).
|
||||
if(v === null){ return true } // deletes
|
||||
@ -389,9 +389,9 @@
|
||||
} else
|
||||
if(Gun.is.soul(val = node[field])){
|
||||
gun.get(val, function(err, data){
|
||||
cb.call(gun, err, data); // TODO: Should we attach field here, does map?
|
||||
cb.call(gun, err, data, field); // TODO: Should we attach field here, does map?
|
||||
if(err || !data){ return }
|
||||
gun._.on('node').emit({soul: Gun.is.soul(val)});
|
||||
gun._.on('node').emit({soul: Gun.is.soul(val), field: null, from: $.soul, at: field});
|
||||
});
|
||||
gun._.on('soul').emit({soul: Gun.is.soul(val), field: null, from: $.soul, at: field});
|
||||
} else {
|
||||
@ -410,7 +410,7 @@
|
||||
|
||||
gun._.status('node').event(function($){ // TODO: once per soul on graph. (?)
|
||||
var node = gun.__.graph[$.soul];
|
||||
cb.call(gun, $.field? node[$.field] : Gun.obj.copy(node)); // TODO: at terminating
|
||||
cb.call(gun, $.field? node[$.field] : Gun.obj.copy(node), $.field || $.at); // TODO: at terminating
|
||||
});
|
||||
|
||||
return gun;
|
||||
@ -531,14 +531,17 @@
|
||||
Gun.obj.map(node, function(val, field){
|
||||
if(Gun._.meta == field){ return }
|
||||
if(Gun.is.soul(val)){
|
||||
gun.get(val).val(function(node){ // TODO: should map have support for `.not`? error?
|
||||
cb.call(this, node, field); // TODO: Should this be NodeJS style or not?
|
||||
gun._.on('node').emit({soul: Gun.is.soul(val)}); // TODO: Same as above, include field?
|
||||
gun.get(val, function(err, data){ // TODO: should map have support for `.not`? error?
|
||||
if(err || !data){ return } // TODO: Handle this!
|
||||
cb.call(this, data, field);
|
||||
gun._.on('node').emit({soul: Gun.is.soul(val), field: null, from: $.soul, at: field});
|
||||
});
|
||||
gun._.on('soul').emit({soul: Gun.is.soul(val), field: null, from: $.soul, at: field});
|
||||
} else {
|
||||
if(opt.node){ return } // {node: true} maps over only sub nodes.
|
||||
cb.call(gun, val, field);
|
||||
gun._.on('soul').emit({soul: $.soul, field: field});
|
||||
gun._.on('node').emit({soul: $.soul, field: field});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -6,7 +6,6 @@
|
||||
}
|
||||
var s = this;
|
||||
s.on = a.on.create();
|
||||
s.mime = require('mime');
|
||||
s.AWS = require('aws-sdk');
|
||||
s.config = {};
|
||||
opt = opt || {};
|
||||
@ -38,7 +37,7 @@
|
||||
m.Key = m.Key || key;
|
||||
if(a.obj.is(o) || a.list.is(o)){
|
||||
m.Body = a.text.ify(o);
|
||||
m.ContentType = this.mime.lookup('json')
|
||||
m.ContentType = 'application/json';
|
||||
} else {
|
||||
m.Body = a.text.is(o)? o : a.text.ify(o);
|
||||
}
|
||||
@ -74,7 +73,7 @@
|
||||
if(e || !r){ return s.on(id).emit(e) }
|
||||
r.Text = r.text = t = (r.Body||r.body||'').toString('utf8');
|
||||
r.Type = r.type = r.ContentType || (r.headers||{})['content-type'];
|
||||
if(r.type && 'json' === s.mime.extension(r.type)){
|
||||
if(r.type && 'application/json' === r.type){
|
||||
d = a.obj.ify(t);
|
||||
}
|
||||
m = r.Metadata;
|
||||
|
14
lib/wsp.js
14
lib/wsp.js
@ -35,18 +35,18 @@
|
||||
gun.server = gun.server || function(req, res, next){
|
||||
//Gun.log("\n\n GUN SERVER!", req);
|
||||
next = next || function(){};
|
||||
if(!req || !res){ return next() }
|
||||
if(!req.url){ return next() }
|
||||
if(!req.method){ return next() }
|
||||
if(!req || !res){ 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.server.regex.test(msg.url.pathname)){ return next() }
|
||||
if(!gun.server.regex.test(msg.url.pathname)){ return next(), false }
|
||||
if(msg.url.pathname.replace(gun.server.regex,'').slice(0,3).toLowerCase() === '.js'){
|
||||
res.writeHead(200, {'Content-Type': 'text/javascript'});
|
||||
res.end(gun.server.js = gun.server.js || require('fs').readFileSync(__dirname + '/../gun.js')); // gun server is caching the gun library for the client
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
http(req, res, function(req, res){
|
||||
return http(req, res, function(req, res){
|
||||
if(!req){ return next() }
|
||||
var tab, cb = res = require('./jsonp')(req, res);
|
||||
if(req.headers && (tab = req.headers['gun-sid'])){
|
||||
@ -72,7 +72,7 @@
|
||||
}
|
||||
}
|
||||
gun.__.opt.hooks.transport(req, cb);
|
||||
});
|
||||
}), true;
|
||||
}
|
||||
gun.server.on = gun.server.on || Gun.on.create();
|
||||
gun.__.opt.poll = gun.__.opt.poll || opt.poll || 1;
|
||||
|
@ -1,24 +1,21 @@
|
||||
{
|
||||
"name": "gun",
|
||||
"version": "0.1.5",
|
||||
"version": "0.2.0",
|
||||
"author": "Mark Nadal",
|
||||
"description": "Graph engine.",
|
||||
"engines": {
|
||||
"node": "~>0.6.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"mime": "~>1.2.11",
|
||||
"aws-sdk": "~>2.0.0",
|
||||
"formidable": "~>1.0.15",
|
||||
"ws": "~>0.4.32",
|
||||
"request": "~>2.39.0"
|
||||
"ws": "~>0.4.32"
|
||||
},
|
||||
"devDependencies": {
|
||||
"mocha": "~>1.9.0"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "node examples/express.js 8080",
|
||||
"prestart": "npm install ./examples",
|
||||
"start": "node examples/http.js 8080",
|
||||
"test": "mocha"
|
||||
}
|
||||
}
|
||||
|
@ -6,29 +6,28 @@ describe('All', function(){
|
||||
var gun = Gun();
|
||||
|
||||
it('map chain', function(done){
|
||||
var c = 0, map = gun.put({a: {here: 'you'}, b: {go: 'dear'}, c: {sir: '!'} });
|
||||
map.map().val(function(obj, field){
|
||||
c++;
|
||||
if(field === 'a'){
|
||||
var set = gun.put({a: {here: 'you'}, b: {go: 'dear'}, c: {sir: '!'} });
|
||||
set.map().val(function(obj, field){
|
||||
if(obj.here){
|
||||
done.a = obj.here;
|
||||
expect(obj.here).to.be('you');
|
||||
}
|
||||
if(field === 'b'){
|
||||
if(obj.go){
|
||||
done.b = obj.go;
|
||||
expect(obj.go).to.be('dear');
|
||||
}
|
||||
if(field === 'c'){
|
||||
if(obj.sir){
|
||||
done.c = obj.sir;
|
||||
expect(obj.sir).to.be('!');
|
||||
}
|
||||
if(c === 3){
|
||||
if(done.a && done.b && done.c){
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('map chain path', function(done){
|
||||
var c = 0, map = gun.put({
|
||||
var set = gun.put({
|
||||
a: {name: "Mark",
|
||||
pet: {coat: "tabby", name: "Hobbes"}
|
||||
}, b: {name: "Alice",
|
||||
@ -37,9 +36,8 @@ describe('All', function(){
|
||||
pet: {coat: "tux", name: "Casper"}
|
||||
}
|
||||
});
|
||||
map.map().path('pet').val(function(obj, field){
|
||||
console.log('test', obj, field);
|
||||
c++;
|
||||
set.map().path('pet').val(function(obj, field){
|
||||
console.log("test", field, obj);
|
||||
if(obj.name === 'Hobbes'){
|
||||
done.hobbes = obj.name;
|
||||
expect(obj.name).to.be('Hobbes');
|
||||
|
@ -1213,7 +1213,7 @@ describe('Gun', function(){
|
||||
|
||||
});
|
||||
|
||||
it('val path put val key', function(done){ // bug discovered from Jose's visualizer
|
||||
it('val path put val key', function(done){ // bug discovered from Jose's visualizer // TODO: still timing issues, 0.6!
|
||||
var gun = Gun(), s = Gun.time.is(), n = function(){ return Gun.time.is() }
|
||||
this.timeout(5000);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user