diff --git a/app.js b/app.js index 1c9e30e979..9c839a94d0 100644 --- a/app.js +++ b/app.js @@ -60,7 +60,7 @@ nconf.file({ file: __dirname + '/config.json' }); - meta = require('./src/meta.js'); + meta = require('./src/meta'); nconf.set('url', nconf.get('base_url') + (nconf.get('use_port') ? ':' + nconf.get('port') : '') + nconf.get('relative_path') + '/'); nconf.set('upload_url', nconf.get('url') + 'uploads/'); @@ -73,60 +73,62 @@ winston.info('Base Configuration OK.'); } - meta.configs.init(function () { - - // - // TODO : figure out reds search after dbal is complete - // - //var reds = require('reds'), - // db = require('./src/database'); - /*reds.createClient = function () { - return reds.client || (reds.client = db); - };*/ - - var templates = require('./public/src/templates'), - translator = require('./public/src/translator'), - webserver = require('./src/webserver'), - SocketIO = require('socket.io').listen(global.server, { log: false, transports: ['websocket', 'xhr-polling', 'jsonp-polling', 'flashsocket'], 'browser client minification': true}), - websockets = require('./src/websockets'), - plugins = require('./src/plugins'), - notifications = require('./src/notifications'), - upgrade = require('./src/upgrade'); - - upgrade.check(function(schema_ok) { - if (schema_ok || nconf.get('check-schema') === false) { - websockets.init(SocketIO); - console.log('calling plugins init'); - plugins.init(); - global.templates = {}; - global.translator = translator; - - translator.loadServer(); - - var customTemplates = meta.config['theme:templates'] ? path.join(__dirname, 'node_modules', meta.config['theme:id'], meta.config['theme:templates']) : false; - - // todo: replace below with read directory code, derp. - templates.init([ - 'header', 'footer', 'logout', 'outgoing', 'admin/header', 'admin/footer', 'admin/index', - 'emails/reset', 'emails/reset_plaintext', 'emails/email_confirm', 'emails/email_confirm_plaintext', - 'emails/header', 'emails/footer', - - 'noscript/header', 'noscript/home', 'noscript/category', 'noscript/topic' - ], customTemplates); - - - plugins.ready(function() { - templates.ready(webserver.init); - }); - - notifications.init(); - } else { - winston.warn('Your NodeBB schema is out-of-date. Please run the following command to bring your dataset up to spec:'); - winston.warn(' node app --upgrade'); - winston.warn('To ignore this error (not recommended):'); - winston.warn(' node app --no-check-schema') - process.exit(); - } + require('./src/database').init(function(err) { + meta.configs.init(function () { + + // + // TODO : figure out reds search after dbal is complete + // + //var reds = require('reds'), + // db = require('./src/database'); + /*reds.createClient = function () { + return reds.client || (reds.client = db); + };*/ + + var templates = require('./public/src/templates'), + translator = require('./public/src/translator'), + webserver = require('./src/webserver'), + SocketIO = require('socket.io').listen(global.server, { log: false, transports: ['websocket', 'xhr-polling', 'jsonp-polling', 'flashsocket'], 'browser client minification': true}), + websockets = require('./src/websockets'), + plugins = require('./src/plugins'), + notifications = require('./src/notifications'), + upgrade = require('./src/upgrade'); + + upgrade.check(function(schema_ok) { + if (schema_ok || nconf.get('check-schema') === false) { + websockets.init(SocketIO); + + plugins.init(); + global.templates = {}; + global.translator = translator; + + translator.loadServer(); + + var customTemplates = meta.config['theme:templates'] ? path.join(__dirname, 'node_modules', meta.config['theme:id'], meta.config['theme:templates']) : false; + + // todo: replace below with read directory code, derp. + templates.init([ + 'header', 'footer', 'logout', 'outgoing', 'admin/header', 'admin/footer', 'admin/index', + 'emails/reset', 'emails/reset_plaintext', 'emails/email_confirm', 'emails/email_confirm_plaintext', + 'emails/header', 'emails/footer', + + 'noscript/header', 'noscript/home', 'noscript/category', 'noscript/topic' + ], customTemplates); + + + plugins.ready(function() { + templates.ready(webserver.init); + }); + + notifications.init(); + } else { + winston.warn('Your NodeBB schema is out-of-date. Please run the following command to bring your dataset up to spec:'); + winston.warn(' node app --upgrade'); + winston.warn('To ignore this error (not recommended):'); + winston.warn(' node app --no-check-schema') + process.exit(); + } + }); }); }); } else if (nconf.get('setup') || nconf.get('install') || !fs.existsSync(__dirname + '/config.json')) { diff --git a/src/database/mongo.js b/src/database/mongo.js index 6d3b4f6e5c..801abb6dd7 100644 --- a/src/database/mongo.js +++ b/src/database/mongo.js @@ -2,9 +2,7 @@ (function(module) { 'use strict'; - var Db = require('mongodb').Db, - mongoClient = require('mongodb').MongoClient, - Server = require('mongodb').Server, + var mongoClient = require('mongodb').MongoClient, winston = require('winston'), nconf = require('nconf'), express = require('express'), @@ -12,45 +10,36 @@ mongoHost = nconf.get('mongo:host'), db; + module.init = function(callback) { + mongoClient.connect('mongodb://'+ mongoHost + ':' + nconf.get('mongo:port') + '/' + nconf.get('mongo:database'), function(err, _db) { + db = _db; + console.log('WE ARE CONNECTED'); - var db = new Db(nconf.get('mongo:database'), new Server(mongoHost, nconf.get('mongo:port')), {w:1}); - //console.log(db.collection); + if(err) { + winston.error("NodeBB could not connect to your Mongo database. Mongo returned the following error: " + err.message); + process.exit(); + } - db.open(function(err, _db) { - //mongoClient.connect('mongodb://'+ mongoHost + ':' + nconf.get('mongo:port') + '/' + nconf.get('mongo:database'), function(err, _db) { - console.log('WE ARE CONNECTED'); - if(err) { - winston.error("NodeBB could not connect to your Mongo database. Mongo returned the following error: " + err.message); - process.exit(); - } - - // TODO: fill out settings.db - module.sessionStore = new mongoStore({ - db: db - }); - - db.collection('objects').findOne({_key:'config'}, {timeout:true}, function(err, item) { - console.log('fail'); - console.log(item); - callback(err, item); - }); - - }); + // TODO: fill out settings.db + module.sessionStore = new mongoStore({ + db: db + }); - db.createCollection('objects', function(err, collection) { - console.log('collection created', err, collection); - }); - db.createCollection('sets', function(err, collection) { + db.createCollection('objects', function(err, collection) { + }); - }); + db.createCollection('sets', function(err, collection) { + }); - - // look up how its done in mongo - /*if (nconf.get('mongo:password')) { - redisClient.auth(nconf.get('mongo:password')); + callback(err); + }); + // look up how its done in mongo + /*if (nconf.get('mongo:password')) { + redisClient.auth(nconf.get('mongo:password')); + } + */ } - */ // @@ -97,18 +86,46 @@ module.getObject = function(key, callback) { console.log('calling findOne'); - db.collection('objects').findOne({_key:key}, {timeout:true},function(err, item) { + db.collection('objects').findOne({_key:key}, function(err, item) { console.log(item); callback(err, item); }); } module.getObjectField = function(key, field, callback) { - throw new Error('not-implemented'); + module.getObjectFields(key, [field], function(err, data) { + if(err) { + return callback(err); + } + + callback(null, data[field]); + }) } module.getObjectFields = function(key, fields, callback) { - throw new Error('not-implemented'); + + var _fields = {}; + for(var i=0; i=0) { /* If redis.host contains a path name character, use the unix dom sock connection. ie, /tmp/redis.sock */ redisClient = redis.createClient(nconf.get('redis:host')); @@ -20,14 +21,13 @@ redisClient = redis.createClient(nconf.get('redis:port'), nconf.get('redis:host')); } + module.client = redisClient; + module.sessionStore = new connectRedis({ client: redisClient, ttl: 60 * 60 * 24 * 30 }); - module.client = redisClient; - module.type = 'redis'; - if (nconf.get('redis:password')) { redisClient.auth(nconf.get('redis:password')); } @@ -43,6 +43,11 @@ }); } + module.init = function(callback) { + callback(null); + } + + /* * A possibly more efficient way of doing multiple sismember calls */ diff --git a/src/plugins.js b/src/plugins.js index 38f4db2d93..0ba6eae81d 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -18,7 +18,6 @@ var fs = require('fs'), Plugins.readyEvent = new eventEmitter; Plugins.init = function() { - console.log('plugins init called'); if (Plugins.initialized) { return; } @@ -39,7 +38,7 @@ var fs = require('fs'), winston.info('[plugins] Plugins OK'); } Plugins.initialized = true; - plugins.readyEvent.emit('ready'); + Plugins.readyEvent.emit('ready'); }); }; diff --git a/src/upgrade.js b/src/upgrade.js index 3ba15a97e2..49bedc2a2c 100644 --- a/src/upgrade.js +++ b/src/upgrade.js @@ -1,10 +1,9 @@ "use strict"; -var db = require('./database'), +var //db = require('./database'), // TODO: temp until upgrade is figured out with dbal, - // db.client is redisClient for now - RDB = db.client, + RDB = require('./database/redis').client, async = require('async'), winston = require('winston'),