mirror of
https://github.com/YMFE/yapi.git
synced 2025-01-30 13:20:24 +08:00
Merge pull request #226 from wei772/master
支持MongoDB --authenticationDatabase 连接
This commit is contained in:
commit
a52de8d51b
@ -3,10 +3,11 @@
|
|||||||
"adminAccount": "admin@admin.com",
|
"adminAccount": "admin@admin.com",
|
||||||
"db": {
|
"db": {
|
||||||
"servername": "127.0.0.1",
|
"servername": "127.0.0.1",
|
||||||
"DATABASE": "yapi",
|
"DATABASE": "yapi",
|
||||||
"port": 27017,
|
"port": 27017,
|
||||||
"user": "test1",
|
"user": "test1",
|
||||||
"pass": "test1"
|
"pass": "test1",
|
||||||
|
"authSource": ""
|
||||||
},
|
},
|
||||||
"mail": {
|
"mail": {
|
||||||
"enable": true,
|
"enable": true,
|
||||||
@ -14,8 +15,8 @@
|
|||||||
"port": 465,
|
"port": 465,
|
||||||
"from": "***@163.com",
|
"from": "***@163.com",
|
||||||
"auth": {
|
"auth": {
|
||||||
"user": "***@163.com",
|
"user": "***@163.com",
|
||||||
"pass": "*****"
|
"pass": "*****"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -24,13 +24,21 @@ function connect(callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let db = mongoose.connect(`mongodb://${config.db.servername}:${config.db.port}/${config.db.DATABASE}`, options, function(err){
|
var connectString = `mongodb://${config.db.servername}:${config.db.port}/${config.db.DATABASE}`;
|
||||||
if(err){
|
if (config.db.authSource) {
|
||||||
yapi.commons.log(err +', mongodb Authentication failed', 'error');
|
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 () {
|
db.then(function () {
|
||||||
yapi.commons.log('mongodb load success...');
|
yapi.commons.log('mongodb load success...');
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user