-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
35 lines (29 loc) · 943 Bytes
/
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
import cors from "cors";
import cookieParser from "cookie-parser";
import usersRoutes from "./routes/userRoute";
import wifiRoute from "./routes/wifiRoute";
import {CLIENT_URL, SERVER_PORT} from "./config/settings";
import {config} from "./config/mikro-orm";
import logger from "./config/logger";
import express, {Application} from "express";
import {EntityManager, MikroORM} from "@mikro-orm/core";
import logging from "./middleware/loggingMiddleware";
const app: Application = express();
export const DI = {} as {
orm: MikroORM,
em: EntityManager
};
app.use(express.json());
app.use(cors({
credentials: true,
origin: [CLIENT_URL]
}));
app.use(cookieParser());
app.use(logging);
app.use("/api/users", usersRoutes);
app.use("/api/wifi", wifiRoute);
app.listen(SERVER_PORT, async () => {
DI.orm = await MikroORM.init(config);
DI.em = DI.orm.em.fork();
logger.info(`Server Started on port ${SERVER_PORT}`);
});