fix pubsub when only mongodb is used

v1.18.x
Barış Soner Uşaklı 7 years ago
parent 6d155ded11
commit 8263f81d0c

@ -62,7 +62,7 @@ mongoModule.questions = [
mongoModule.helpers = mongoModule.helpers || {}; mongoModule.helpers = mongoModule.helpers || {};
mongoModule.helpers.mongo = require('./mongo/helpers'); mongoModule.helpers.mongo = require('./mongo/helpers');
function getConnectionString() { mongoModule.getConnectionString = function () {
var usernamePassword = ''; var usernamePassword = '';
if (nconf.get('mongo:username') && nconf.get('mongo:password')) { if (nconf.get('mongo:username') && nconf.get('mongo:password')) {
usernamePassword = nconf.get('mongo:username') + ':' + encodeURIComponent(nconf.get('mongo:password')) + '@'; usernamePassword = nconf.get('mongo:username') + ':' + encodeURIComponent(nconf.get('mongo:password')) + '@';
@ -90,15 +90,9 @@ function getConnectionString() {
} }
return nconf.get('mongo:uri') || 'mongodb://' + usernamePassword + servers.join() + '/' + nconf.get('mongo:database'); return nconf.get('mongo:uri') || 'mongodb://' + usernamePassword + servers.join() + '/' + nconf.get('mongo:database');
} };
mongoModule.init = function (callback) {
callback = callback || function () { };
var mongoClient = require('mongodb').MongoClient;
var connString = getConnectionString();
mongoModule.getConnectionOptions = function () {
var connOptions = { var connOptions = {
poolSize: 10, poolSize: 10,
reconnectTries: 3600, reconnectTries: 3600,
@ -106,7 +100,16 @@ mongoModule.init = function (callback) {
autoReconnect: true, autoReconnect: true,
}; };
connOptions = _.merge(connOptions, nconf.get('mongo:options') || {}); return _.merge(connOptions, nconf.get('mongo:options') || {});
};
mongoModule.init = function (callback) {
callback = callback || function () { };
var mongoClient = require('mongodb').MongoClient;
var connString = mongoModule.getConnectionString();
var connOptions = mongoModule.getConnectionOptions();
mongoClient.connect(connString, connOptions, function (err, _client) { mongoClient.connect(connString, connOptions, function (err, _client) {
if (err) { if (err) {
@ -272,5 +275,5 @@ mongoModule.close = function (callback) {
mongoModule.socketAdapter = function () { mongoModule.socketAdapter = function () {
var mongoAdapter = require('socket.io-adapter-mongo'); var mongoAdapter = require('socket.io-adapter-mongo');
return mongoAdapter(getConnectionString()); return mongoAdapter(mongoModule.getConnectionString());
}; };

@ -1,8 +1,8 @@
'use strict'; 'use strict';
var mubsub = require('mubsub'); var mubsub = require('mubsub-nbb');
var db = require('../mongo'); var db = require('../mongo');
var client = mubsub(db.client); var client = mubsub(db.getConnectionString(), db.getConnectionOptions());
module.exports = client.channel('pubsub'); module.exports = client.channel('pubsub');

Loading…
Cancel
Save