-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
36 lines (31 loc) · 816 Bytes
/
main.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
const app = require("./server");
const port = process.env.PORT || 3002;
function logErrors(err, req, res, next) {
console.error(err.stack);
next(err);
}
app.use(logErrors);
function clientErrorHandler(err, req, res, next) {
if (req.xhr) {
res.status(500).send({ error: "Something failed!" });
} else {
next(err);
}
}
app.use(clientErrorHandler);
function errorHandler(err, req, res, next) {
res.status(500);
res.render("error", { error: err });
}
app.use(errorHandler);
app.listen(port, "0.0.0.0", () => {
console.log(`🚀 it's listening on ${port}`);
});
process.on("unhandledRejection", (p) => {
console.error("unhandledRejection", p);
throw new Error(p);
});
process.on("uncaughtException", function (err) {
console.error("uncaughtException", err);
throw new Error(err);
});