wildduck/lib/db.js
Andris Reinman c172fe9779 update
2017-05-02 16:21:56 +03:00

41 lines
1.2 KiB
JavaScript

'use strict';
const config = require('config');
const tools = require('./tools');
const mongodb = require('mongodb');
const redis = require('redis');
const MongoClient = mongodb.MongoClient;
module.exports.senderDb = false;
module.exports.database = false;
module.exports.redis = false;
module.exports.redisConfig = false;
module.exports.connect = callback => {
MongoClient.connect(config.mongo, (err, database) => {
if (err) {
return callback(err);
}
module.exports.database = database;
module.exports.redisConfig = tools.redisConfig(config.redis);
module.exports.redis = redis.createClient(module.exports.redisConfig);
if (!config.sender.enabled) {
return callback(null, database);
}
if (!config.sender.mongo) {
module.exports.senderDb = database;
return callback(null, database);
}
MongoClient.connect(config.sender.mongo, (err, forwarderDatabase) => {
if (err) {
database.close();
return callback(err);
}
module.exports.senderDb = forwarderDatabase;
return callback(null, database);
});
});
};