-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
63 lines (55 loc) · 1.34 KB
/
app.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
52
53
54
55
56
57
58
59
60
61
62
63
const express = require("express");
const expressLogger = require("express-bunyan-logger");
const cors = require("cors");
const router = require("./routes");
require("./models");
process.on("uncaughtException", (e) => {
console.log(e);
});
const app = express();
app.use(
express.json({
inflate: true, // Enables handling deflated (compressed) bodies; when disabled, deflated bodies are rejected.
limit: "10mb", // Controls the maximum request body size. Default unit is number of bytes,
strict: true, // Enables only accepting arrays and objects
})
);
app.use(
express.urlencoded({
inflate: true,
limit: "10mb",
extended: true,
})
);
app.use(
expressLogger({
excludes: [
"headers",
"req",
"user-agent",
"short-body",
"http-version",
"req-headers",
"res-headers",
"body",
"res",
], // remove extra details from log
})
);
app.use(cors());
// routes
app.use("/api", router);
// catch 404 later
app.use((req, res) => {
return res.status(404).send("Error 404, Route not found");
});
// error handling
app.use((err, req, res, next) => {
// for now log the error and return 500; need to handle it differently in future
if (res.headersSent) {
return next(err);
}
req.log.error(err);
return res.status(500).send(err.message);
});
module.exports = app;