MCPcopy
hub / github.com/YMFE/yapi / connect

Function connect

server/utils/db.js:15–67  ·  view source on GitHub ↗
(callback)

Source from the content-addressed store, hash-verified

13}
14
15function connect(callback) {
16 mongoose.Promise = global.Promise;
17 mongoose.set('useNewUrlParser', true);
18 mongoose.set('useFindAndModify', false);
19 mongoose.set('useCreateIndex', true);
20
21 let config = yapi.WEBCONFIG;
22 let options = {useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true};
23
24 if (config.db.user) {
25 options.user = config.db.user;
26 options.pass = config.db.pass;
27 }
28
29 options = Object.assign({}, options, config.db.options)
30
31 var connectString = '';
32
33 if(config.db.connectString){
34 connectString = config.db.connectString;
35 }else{
36 connectString = `mongodb://${config.db.servername}:${config.db.port}/${config.db.DATABASE}`;
37 if (config.db.authSource) {
38 connectString = connectString + `?authSource=${config.db.authSource}`;
39 }
40 }
41
42 let db = mongoose.connect(
43 connectString,
44 options,
45 function(err) {
46 if (err) {
47 yapi.commons.log(err + ', mongodb Authentication failed', 'error');
48 }
49 }
50 );
51
52 db.then(
53 function() {
54 yapi.commons.log('mongodb load success...');
55
56 if (typeof callback === 'function') {
57 callback.call(db);
58 }
59 },
60 function(err) {
61 yapi.commons.log(err + 'mongodb connect error', 'error');
62 }
63 );
64
65 autoIncrement.initialize(db);
66 return db;
67}
68
69yapi.db = model;
70

Callers 15

ProjectCard.jsFile · 0.85
VariablesSelect.jsFile · 0.85
Breadcrumb.jsFile · 0.85
GuideBtnsClass · 0.85
Search.jsFile · 0.85
TimeLine.jsFile · 0.85
Reg.jsFile · 0.85
Login.jsFile · 0.85
LoginWrap.jsFile · 0.85
AddProject.jsFile · 0.85
FollowsClass · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected