forked from mongo-express/mongo-express
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (39 loc) · 1.2 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//Add routes from other files
var
database = require('./database')
, collection = require('./collection')
, document = require('./document')
;
var routes = function(config) {
var exp = {};
exp.viewDatabase = database(config).viewDatabase;
exp.viewCollection = collection(config).viewCollection;
exp.addCollection = collection(config).addCollection;
exp.deleteCollection = collection(config).deleteCollection;
exp.renameCollection = collection(config).renameCollection;
exp.exportCollection = collection(config).exportCollection;
exp.viewDocument = document(config).viewDocument;
exp.updateDocument = document(config).updateDocument;
exp.deleteDocument = document(config).deleteDocument;
exp.addDocument = document(config).addDocument;
//Homepage route
exp.index = function(req, res) {
var ctx = {
title: 'Mongo Express',
info: false
};
if (typeof req.adminDb == "undefined") {
return res.render('index');
}
req.adminDb.serverStatus(function(err, info) {
if (err) {
//TODO: handle error
console.error(err);
}
ctx.info = info;
res.render('index', ctx);
});
};
return exp;
};
module.exports = routes;