-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
41 lines (33 loc) · 1.07 KB
/
index.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
import bodyParser from "body-parser";
import cookieParser from "cookie-parser";
import cors from "cors";
import dotenv from "dotenv";
import express from "express";
import "express-async-errors";
import morgan from "morgan";
import { useErrorHandler, useNotFound } from "./middlewares/";
import corsOptions from "./utils/corsOptions";
import { accessLogStream, logger } from "./utils";
import { PORT, IS_PRODUCTION, MORGAN_CONFIG } from "./constants/app";
import helmet from "helmet";
import baseRouter from "./features/base/route";
import swaggerRouter from "./swagger";
dotenv.config();
const app = express();
app.use(cors(corsOptions));
app.use(cookieParser());
app.use(bodyParser.json({}));
app.use(
morgan(MORGAN_CONFIG, {
stream: IS_PRODUCTION ? accessLogStream : process.stdout,
})
);
app.use(helmet());
app.use(bodyParser.urlencoded({ extended: true }));
app.use("/api/", baseRouter);
app.use("/api-docs", swaggerRouter);
app.use(useNotFound);
app.use(useErrorHandler);
export const server = app.listen(PORT, () => {
logger.info(`Server running on port ${PORT}`);
});