-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
39 lines (32 loc) · 1.06 KB
/
main.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
import express, { Express, NextFunction, Request, Response } from "express";
import cors from "cors";
import dotenv from "dotenv";
import logger from "morgan";
import cookieParser from "cookie-parser";
import "module-alias/register";
import { setup } from "./di-setup";
setup();
import indexRouter from "./src/modules";
import { exceptionMiddleware } from "./lib";
const mode = process.env.NODE_ENV || "production";
if (mode === "production") {
dotenv.config();
} else {
dotenv.config({ path: `.${mode}.env` });
}
const app: Express = express();
const port = process.env.PORT || 3001;
app.use(logger("dev"));
app.use(cors({ credentials: true, origin: true }));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use("/api", indexRouter);
app.use(function (err: any, req: Request, res: Response, next: NextFunction) {
exceptionMiddleware(err, req, res);
});
app.listen(port, () => {
console.clear();
console.log(`[server]: Server is running at http://localhost:${port}`);
console.log(`[server]: Mode: ${mode}`);
});