-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.ts
More file actions
37 lines (26 loc) · 998 Bytes
/
app.ts
File metadata and controls
37 lines (26 loc) · 998 Bytes
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 express, { Response, Request, Application, NextFunction} from "express";
import cors from "cors";
import morgan from "morgan";
import { AppError, HttpCode } from "./Utils/AppError";
import { ErrorHandler } from "./Middlewares/ErrorHandler/ErrorHandler";
import userrouter from "./Routers/users.routes";
import productrouter from "./Routers/product.routes";
export const AppConfig = (app: Application) =>{
app.use(express.json());
app.use(cors());
app.use(morgan("dev"));
// app.use(express.urlencoded());
// Routes configuration:
app.use("/api/users", userrouter);
app.use("/api/products", productrouter)
app.all("*", (req: Request, res: Response, next: NextFunction) =>{
next(
new AppError({
message: `This route ${req.originalUrl} does not exist`,
httpCode: HttpCode.NOT_FOUND
})
)
});
// Errorhandler should be at the bottom of your code
app.use(ErrorHandler)
}