Commit 225585e3 authored by Cédric Moreau's avatar Cédric Moreau

Asynchronous initialization of nodecoin

parent 89fda30d
......@@ -59,45 +59,54 @@ module.exports.express = {
app.get( '/udc/amendments/submit', web.amendments.submit);
},
app: function (config) {
var app = express();
app: function (config, onLoaded) {
configurer(config).parseFiles(function (err) {
if(!err){
console.log("Initkeys loaded.");
async.parallel({
loadInitKeys: function(callback){
configurer(config).parseFiles(function (err) {
if(!err){
console.log("Initkeys loaded.");
}
else{
console.log(err);
}
callback(err);
});
},
loadMongoDB: function(callback){
// Bootstraps models
nodecoin.database.init();
nodecoin.database.connect(config, function (err) {
if(!err)
console.log("Connected to MongoDB.");
else
console.log("Error connecting to DB: " + err);
callback(err);
});
}
else{
console.log(err);
}
});
// Bootstraps models
nodecoin.database.init();
nodecoin.database.connect(config, function (err) {
if(!err)
console.log("Connected to MongoDB.");
else
console.log("Error connecting to DB: " + err);
});
},
function(err, results) {
var app = express();
// all environments
app.set('config', config);
app.set('port', process.env.PORT || config.server.port);
app.use(express.favicon(__dirname + '/../public/favicon.ico'));
app.use(express.static(__dirname + '/../public'));
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser('your secret here'));
app.use(express.session());
app.use(app.router);
// all environments
app.set('config', config);
app.set('port', process.env.PORT || config.server.port);
app.use(express.favicon(__dirname + '/../public/favicon.ico'));
app.use(express.static(__dirname + '/../public'));
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser('your secret here'));
app.use(express.session());
app.use(app.router);
// development only
if ('development' == app.get('env')) {
app.use(express.errorHandler());
}
// development only
if ('development' == app.get('env')) {
app.use(express.errorHandler());
}
this.route(app);
this.route(app);
return app;
onLoaded(err, app);
}.bind(this));
}
};
\ No newline at end of file
#!/usr/bin/env node
var config = require('../config/config');
var nodecoin = require('../lib/nodecoin');
var nodecoin = require('../app/lib/nodecoin');
var http = require('http');
var program = require('commander');
......@@ -35,23 +35,23 @@ for(var i in program.initKeys){
config.initKeys.push({path: program.initKeys[i]});
}
var app = nodecoin.express.app(config);
if(!config.server.ipv4address){
http.createServer(app).listen(app.get('port'), function(){
console.log('NodeCoin server listening on port ' + app.get('port'));
console.log("Currency name: " + app.get('config').currency.name);
});
}
if(config.server.ipv4address){
http.createServer(app).listen(app.get('port'), config.server.ipv4address, function(){
console.log('NodeCoin server listening on ' + config.server.ipv4address + ' port ' + app.get('port'));
});
}
if(config.server.ipv6address){
http.createServer(app).listen(app.get('port'), config.server.ipv6address, function(){
console.log('NodeCoin server listening on ' + config.server.ipv6address + ' port ' + app.get('port'));
});
}
\ No newline at end of file
nodecoin.express.app(config, function (err, app) {
if(!config.server.ipv4address){
http.createServer(app).listen(app.get('port'), function(){
console.log('NodeCoin server listening on port ' + app.get('port'));
console.log("Currency name: " + app.get('config').currency.name);
});
}
if(config.server.ipv4address){
http.createServer(app).listen(app.get('port'), config.server.ipv4address, function(){
console.log('NodeCoin server listening on ' + config.server.ipv4address + ' port ' + app.get('port'));
});
}
if(config.server.ipv6address){
http.createServer(app).listen(app.get('port'), config.server.ipv6address, function(){
console.log('NodeCoin server listening on ' + config.server.ipv6address + ' port ' + app.get('port'));
});
}
});
......@@ -11,8 +11,6 @@ var config = {
initKeys: []
};
var app = nodecoin.express.app(config);
var gets = [
{should: 501, url: '/udc/amendments/view/[000001]/members'},
{should: 501, url: '/udc/amendments/view/[000001]/self'},
......@@ -51,6 +49,14 @@ function testPOST(url, should) {
});
}
var app;
before(function (done) {
nodecoin.express.app(config, function (err, appReady) {
app = appReady;
done();
});
});
for (var i = 0; i < gets.length; i++) {
testGET(gets[i].url, gets[i].should);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment