up mongo deps, create session store after db.authenticate

v1.18.x
barisusakli 8 years ago
parent bfcef27c47
commit 6d97c4cec8

@ -27,7 +27,7 @@
"compression": "^1.1.0", "compression": "^1.1.0",
"connect-ensure-login": "^0.1.1", "connect-ensure-login": "^0.1.1",
"connect-flash": "^0.1.1", "connect-flash": "^0.1.1",
"connect-mongo": "~1.1.0", "connect-mongo": "1.3.2",
"connect-multiparty": "^2.0.0", "connect-multiparty": "^2.0.0",
"connect-redis": "~3.1.0", "connect-redis": "~3.1.0",
"cookie-parser": "^1.3.3", "cookie-parser": "^1.3.3",
@ -48,7 +48,7 @@
"mime": "^1.3.4", "mime": "^1.3.4",
"minimist": "^1.1.1", "minimist": "^1.1.1",
"mkdirp": "~0.5.0", "mkdirp": "~0.5.0",
"mongodb": "~2.1.3", "mongodb": "2.2.10",
"morgan": "^1.3.2", "morgan": "^1.3.2",
"mousetrap": "^1.5.3", "mousetrap": "^1.5.3",
"nconf": "~0.8.2", "nconf": "~0.8.2",

@ -3,13 +3,13 @@
(function (module) { (function (module) {
var winston = require('winston'), var winston = require('winston');
async = require('async'), var async = require('async');
nconf = require('nconf'), var nconf = require('nconf');
session = require('express-session'), var session = require('express-session');
_ = require('underscore'), var _ = require('underscore');
semver = require('semver'), var semver = require('semver');
db, mongoClient; var db;
_.mixin(require('underscore.deep')); _.mixin(require('underscore.deep'));
@ -48,15 +48,9 @@
module.init = function (callback) { module.init = function (callback) {
callback = callback || function () {}; callback = callback || function () {};
var mongoClient;
try { try {
var sessionStore;
mongoClient = require('mongodb').MongoClient; mongoClient = require('mongodb').MongoClient;
if (!nconf.get('redis')) {
sessionStore = require('connect-mongo/es5')(session);
} else {
sessionStore = require('connect-redis')(session);
}
} catch (err) { } catch (err) {
winston.error('Unable to initialize MongoDB! Is MongoDB installed? Error :' + err.message); winston.error('Unable to initialize MongoDB! Is MongoDB installed? Error :' + err.message);
return callback(err); return callback(err);
@ -106,22 +100,6 @@
module.client = db; module.client = db;
if (!nconf.get('redis')) {
module.sessionStore = new sessionStore({
db: db
});
} else {
// Initial Redis database
var rdb = require('./redis');
// Create a new redis connection and store it in module (skeleton)
rdb.client = rdb.connect();
module.sessionStore = new sessionStore({
client: rdb.client,
ttl: 60 * 60 * 24 * 14
});
}
require('./mongo/main')(db, module); require('./mongo/main')(db, module);
require('./mongo/hash')(db, module); require('./mongo/hash')(db, module);
require('./mongo/sets')(db, module); require('./mongo/sets')(db, module);
@ -131,16 +109,36 @@
if (nconf.get('mongo:password') && nconf.get('mongo:username')) { if (nconf.get('mongo:password') && nconf.get('mongo:username')) {
db.authenticate(nconf.get('mongo:username'), nconf.get('mongo:password'), function (err) { db.authenticate(nconf.get('mongo:username'), nconf.get('mongo:password'), function (err) {
if (err) { if (err) {
winston.error(err.stack); return callback(err);
process.exit();
} }
createSessionStore();
createIndices(); createIndices();
}); });
} else { } else {
winston.warn('You have no mongo password setup!'); winston.warn('You have no mongo password setup!');
createSessionStore();
createIndices(); createIndices();
} }
function createSessionStore() {
var sessionStore;
if (nconf.get('redis')) {
sessionStore = require('connect-redis')(session);
var rdb = require('./redis');
rdb.client = rdb.connect();
module.sessionStore = new sessionStore({
client: rdb.client,
ttl: 60 * 60 * 24 * 14
});
} else if (nconf.get('mongo')) {
sessionStore = require('connect-mongo')(session);
module.sessionStore = new sessionStore({
db: db
});
}
}
function createIndices() { function createIndices() {
winston.info('[database] Checking database indices.'); winston.info('[database] Checking database indices.');
async.parallel([ async.parallel([
@ -151,6 +149,7 @@
if (err) { if (err) {
winston.error('Error creating index ' + err.message); winston.error('Error creating index ' + err.message);
} }
winston.info('[database] Checking database indices done!');
callback(err); callback(err);
}); });
} }

@ -59,7 +59,7 @@
require('./redis/sorted')(redisClient, module); require('./redis/sorted')(redisClient, module);
require('./redis/list')(redisClient, module); require('./redis/list')(redisClient, module);
if(typeof callback === 'function') { if (typeof callback === 'function') {
callback(); callback();
} }
}; };

Loading…
Cancel
Save