-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
41 lines (34 loc) · 1.01 KB
/
app.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 cors from "cors";
import express, { Application, NextFunction, Request, Response } from "express";
import httpStatus from "http-status";
import globalErrorHandler from "./app/middlewares/globalErrorHandler";
import routes from "./app/routes";
const app: Application = express();
app.use(cors());
//parser
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
// app.use('/api/v1/users/', UserRoutes);
// app.use('/api/v1/academic-semesters', AcademicSemesterRoutes);
app.use("/api/v1", routes);
//Testing
// app.get('/', async (req: Request, res: Response, next: NextFunction) => {
// throw new Error('Testing Error logger')
// })
//global error handler
app.use(globalErrorHandler);
//handle not found
app.use((req: Request, res: Response, next: NextFunction) => {
res.status(httpStatus.NOT_FOUND).json({
success: false,
message: "Not Found",
errorMessages: [
{
path: req.originalUrl,
message: "API Not Found",
},
],
});
next();
});
export default app;