-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
34 lines (33 loc) · 1.18 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
import express, { Express } from 'express';
import * as dotenv from 'dotenv';
import helmet from "helmet";
import cors from "cors";
import cookieParser from "cookie-parser";
import { logger } from "./src/shared/logger"
import { connect } from './src/shared/database/mongoose';
import { UseRoutes } from './src/shared/helpers/routes';
import { router as authRoutes, NAME as authName } from "./src/features/authentication/authRoutes"
import { router as tokenRoutes, NAME as tokenName } from "./src/features/token/tokenRoutes"
import { errorHandler } from './src/shared/middleware/errorHandler';
import { checkCsrf } from './src/shared/middleware/csrf';
dotenv.config();
const app: Express = express();
const port = process.env.PORT;
try {
app.use(helmet());
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());
connect().then(_ => {
logger.info("Database connected.");
app.listen(port, () => {
logger.info(`⚡️[server]: Server is running on port ${port}`);
});
})
UseRoutes(app, authName, authRoutes);
UseRoutes(app, tokenName, tokenRoutes);
app.use(errorHandler);
} catch (error) {
logger.error(error);
}