-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
38 lines (30 loc) · 1.04 KB
/
app.ts
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
import globals from "./env/env";
import express from "express";
import cookieParser from "cookie-parser";
import middlewareI18n from "./middlewares/i18n";
import Logger from "./log/logger";
import routes from "./routes";
import Status from "./models/status";
import { logIncoming, logOutgoing } from "./middlewares/log";
import middlewareCore from "./middlewares/core";
import loadEnv from "./env/loader";
import { initDatabase } from "./database/config";
export default (logSuffix?: string, initDb = true) => {
if (initDb) {
loadEnv();
initDatabase();
}
Logger.init(logSuffix);
const app = express();
app.set("trust proxy", globals.env.TRUST_PROXY ? 1 : 0);
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(middlewareI18n);
app.use(logIncoming);
app.use(routes);
app.all("*", (req, res, next) => Status.send(req, next, { status: 404, error: "system.notFound" }));
app.use(logOutgoing);
app.use(middlewareCore);
return app;
};