-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
44 lines (37 loc) · 998 Bytes
/
Copy pathindex.js
File metadata and controls
44 lines (37 loc) · 998 Bytes
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
// Config
const logger = require("./config/logger.js");
const dotenv = require("dotenv");
dotenv.config({ path: "./config/.env" });
const { checkChainId, checkExecutor, checkSafeVersion } = require("./utils/safe");
// App
const app = require("./app.js");
let server;
// MongoDB
const connectDB = require("./config/mongodb");
// Start!
connectDB().then(async () => {
await checkExecutor();
await checkChainId();
await checkSafeVersion();
// connect
server = app.listen(
process.env.PORT || 3000,
logger.info(
`Safe Watcher is running in ${process.env.NODE_ENV} mode on port ${process.env.PORT}`,
),
);
});
// On Unexpected Error
const unexpectedErrorHandler = (error) => {
if (server) {
server.close(() => {
logger.error(error);
logger.info("Server closed");
process.exit(1);
});
} else {
process.exit(1);
}
};
process.on("uncaughtException", unexpectedErrorHandler);
process.on("unhandledRejection", unexpectedErrorHandler);