Merge pull request #226 from wei772/master

支持MongoDB --authenticationDatabase 连接
This commit is contained in:
suxiaoxin 2018-04-10 19:40:05 +08:00 committed by GitHub
commit a52de8d51b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 8 deletions

View File

@ -3,10 +3,11 @@
"adminAccount": "admin@admin.com",
"db": {
"servername": "127.0.0.1",
"DATABASE": "yapi",
"DATABASE": "yapi",
"port": 27017,
"user": "test1",
"pass": "test1"
"pass": "test1",
"authSource": ""
},
"mail": {
"enable": true,
@ -14,8 +15,8 @@
"port": 465,
"from": "***@163.com",
"auth": {
"user": "***@163.com",
"pass": "*****"
"user": "***@163.com",
"pass": "*****"
}
}
}

View File

@ -24,13 +24,21 @@ function connect(callback) {
}
let db = mongoose.connect(`mongodb://${config.db.servername}:${config.db.port}/${config.db.DATABASE}`, options, function(err){
if(err){
yapi.commons.log(err +', mongodb Authentication failed', 'error');
var connectString = `mongodb://${config.db.servername}:${config.db.port}/${config.db.DATABASE}`;
if (config.db.authSource) {
connectString = connectString + `?authSource=${config.db.authSource}`;
}
//yapi.commons.log(connectString);
let db = mongoose.connect(connectString, options, function (err) {
if (err) {
yapi.commons.log(err + ', mongodb Authentication failed', 'error');
}
});
db.then(function () {
yapi.commons.log('mongodb load success...');