-
Notifications
You must be signed in to change notification settings - Fork 6
/
config.js
47 lines (43 loc) · 1011 Bytes
/
config.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
const { MongoClient } = require("mongodb");
const { NODE_ENV, MONGODB } = process.env;
const uri =
MONGODB ||
"mongodb://root:iwb@localhost:27017/?authMechanism=DEFAULT&authSource=admin";
module.exports = {
db(work, res) {
const client = new MongoClient(uri);
const db = client.db("iwb");
return Promise.resolve()
.then(() => {
return work(db);
})
.then((result) => {
res?.(null, result);
client.close();
return result;
})
.catch((err) => {
console.log(err);
client.close();
if (res) {
res(err.message);
} else {
throw err;
}
});
},
};
if (NODE_ENV === "production") {
const buffer = require("log-buffer");
buffer(4096, () => {
return `${new Date().toISOString()}: `;
});
setInterval(() => {
buffer.flush();
}, 5000);
} else {
require("./scripts/enable_slave_debug");
process.on("uncaughtException", (e) => {
console.log(e);
});
}