-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.ts
51 lines (40 loc) · 1.21 KB
/
server.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
39
40
41
42
43
44
45
46
47
48
49
50
51
import "dotenv/config";
import cors from "cors";
import express from "express";
import morgan from "morgan";
import helmet from "helmet";
import expressEjsLayouts from "express-ejs-layouts";
import routes from "./routes";
import { customErrorHandler, NotFoundError } from "./libs";
import pkg from "./package.json" assert { type: "json" };
import connectDB from "./helpers/mongodb";
export const app: express.Application = express();
// const __dirname = process.cwd();
console.log("🚀", "Cat as a Service", "v" + pkg.version);
const isDev: boolean = process.env.NODE_ENV == "production";
console.log(isDev ? "🚀 Production Mode" : "👷 Development Mode");
connectDB();
app.set("layout", "./layouts/layout");
app.set("view engine", "ejs");
app.use(cors());
app.use(helmet());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(morgan(isDev ? "combined" : "dev"));
app.use(expressEjsLayouts);
app.use(express.static("public"));
app.use("/", routes);
app.use((req, res, next) => {
next(new NotFoundError());
});
app.use(
(
error: any,
req: express.Request,
res: express.Response,
next: express.NextFunction
) => {
customErrorHandler(res, error);
}
);
export default app;