From f4b3d37ce1892375de4b378ef12c1b8d1db98456 Mon Sep 17 00:00:00 2001 From: liwei Date: Tue, 10 Apr 2018 18:05:53 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=94=AF=E6=8C=81MongoDB=20=20--authentica?= =?UTF-8?q?tionDatabase=20=20=E8=BF=9E=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/utils/db.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/server/utils/db.js b/server/utils/db.js index ac91bbd3..c454dd4c 100755 --- a/server/utils/db.js +++ b/server/utils/db.js @@ -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...'); From 14e797852ab9762dde03658308d939dd75f1b3f2 Mon Sep 17 00:00:00 2001 From: liwei Date: Tue, 10 Apr 2018 18:19:35 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=B8=80=E8=88=ACauthSource=E4=B8=BAadmin?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config_example.json | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/config_example.json b/config_example.json index cc088875..479bd193 100755 --- a/config_example.json +++ b/config_example.json @@ -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": "*****" } } } \ No newline at end of file