This commit is contained in:
theory 2014-03-17 05:01:21 -06:00
parent eafcf62f98
commit 407263fcd0
6 changed files with 68 additions and 12 deletions

View File

@ -13,7 +13,7 @@ opt.hook = {
})
};
opt.run = [];
opt.run = ['./test/server'];
web(opt);
console.log("Gun @ "+ opt.port);

View File

@ -9,8 +9,9 @@
"theory": "~>0.2.5",
"coalesce": "~>0.1.9b",
"aws-sdk": "~>2.0.0",
"hiredis": "",
"redis": "~>0.10.1",
"mime": "~>1.2.11"
}
, "main": "gun"
, "main": "shots"
}

14
redis.sh Normal file
View File

@ -0,0 +1,14 @@
if [ -e redis-stable ];
then
echo "redis already installed."
else
echo "installing redis"
curl -O http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
make
echo "redis installed"
cd ..
fi
cd redis-stable
src/redis-server

View File

@ -1,7 +1,29 @@
module.exports = require('theory')
('shot',function(a){
require('child_process').exec('redis.sh', function(e, r){
console.log(e,r);
});
/*
var redis = a.redis
, client = redis.createClient();
client.on('error', function(e){
if(!(/ECONNREFUSED/).test(e)){ return }
if(redis.none){ return }
redis.path = '/usr/local/bin/redis-server';
if(!(require('fs').existsSync||require('path').existsSync)(redis.path)){
redis.none = true;
return;
}
if(process.env.gun_redis_lock){ return }
process.env.gun_redis_lock = process.pid;
console.log('gun', process.pid, 'starting redis');
require('child_process').spawn(redis.path).on('exit',function(c,s){
if(process.env.gun_redis_lock == process.pid){
process.env.gun_redis_lock = ''; // 0 and false don't work, cause they are cast to strings!
}
});
});
*/
return function(opt){
opt = opt || {};
opt.src = opt.src || '';
@ -67,15 +89,7 @@ module.exports = require('theory')
else { return 0 }
}
shot.start = function(){
client.on('error', function(e){
if(!(/ECONNREFUSED/).test(e)){ return }
console.log("gun starting redis");
if(!opt.redis.path){
if(!(require('fs').existsSync||require('path').existsSync)('/usr/local/bin/redis-server')){
//path =
}
}
});
};
shot.start();
return {gun: a.gun};

26
test/blah.js Normal file
View File

@ -0,0 +1,26 @@
module.exports=require('theory')
({name: 'blah'
, state: {way:'state', flow:-1}
, invincible: true
, dep: ['../shots']
, init: function(a){
console.log("BLAH");
var blah = {};
blah.put = function(m){
console.log('stream', m);
}
blah.state = function(m){
var w = blah.get(m);
console.log('state', w);
if(w){
m.what.body = 1;
}
a.com.reply(m);
};
blah.get = function(m){
return !a.obj.empty(a(m,'what.form'))? a(m,'what.form')
: !a.obj.empty(a(m,'what.url.query'))? a(m,'what.url.query')
: false ;
};
return blah;
}});

View File

@ -2,8 +2,9 @@ module.exports=require('theory')
({name: 'echo'
, state: {way:'state', flow:-1}
, invincible: true
//, dep: ['../gun']
, dep: ['../shots']
, init: function(a){
console.log("ECHO");
var echo = {};
echo.put = function(m){
console.log('stream', m);