-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.js
44 lines (39 loc) · 1.02 KB
/
server.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
const log = require('./helpers/log');
/**
* @description http watched DB tables
*/
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const config = require('./modules/configReader');
const port = config.api;
const db = require('./modules/DB');
if (port) {
app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({
extended: true,
})); // for parsing application/x-www-form-urlencoded
app.get('/db', (req, res) => {
const tb = db[req.query.tb].db;
if (!tb) {
res.json({
err: 'tb not find',
});
return;
}
tb.find().toArray((err, data) => {
if (err) {
res.json({
success: false,
err,
});
return;
}
res.json({
success: true,
result: data,
});
});
});
app.listen(port, () => log.info(`${config.notifyName} debug server is listening on http://localhost:${port}. F. e., http://localhost:${port}/db?tb=systemDb.`));
}