-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
37 lines (30 loc) · 1.04 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
import { AppError } from "@common/errors/AppError";
import { initialDataPost } from "@infrastructure/database/mocks/DataPost";
import { router } from "@infrastructure/http/routes/route";
import { checkMongoDBConnection } from "@providers/check-mongodb-connection";
import cors from "cors";
import "dotenv/config";
import express, { NextFunction, Request, Response, json } from "express";
import "express-async-errors";
const app = express();
const port = 5000;
app.use(cors());
app.use(json());
app.use(router);
checkMongoDBConnection();
initialDataPost();
// eslint-disable-next-line @typescript-eslint/no-unused-vars
app.use((err: Error, request: Request, response: Response, _: NextFunction) => {
if (err instanceof AppError) {
return response
.status(err.statusCode)
.json({ status: "error", message: err.message });
}
console.error(err);
return response
.status(500)
.json({ status: "error", message: "Internal server error" });
});
app.listen(port, () => {
console.log(`Server starting 🚀 http://localhost:${port}`);
});