mirror of
https://github.com/nodemailer/wildduck.git
synced 2025-01-05 23:51:53 +08:00
47 lines
1.4 KiB
JavaScript
47 lines
1.4 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.gridfs = false;
|
|
module.exports.users = 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.gridfs = config.dbs.gridfs ? database.db(config.dbs.gridfs) : database;
|
|
module.exports.users = config.dbs.users ? database.db(config.dbs.users) : 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);
|
|
});
|
|
});
|
|
};
|