-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
35 lines (27 loc) · 830 Bytes
/
app.js
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 express from "express";
import { router as userRouter } from "./route/userRoute.js";
import { router as postRouter } from "./route/postRoute.js";
import { router as commentRouter } from "./route/commentRoute.js";
import { globalErrorHandler } from "./controller/errorController.js";
import { AppError } from "./utils/AppError.js";
const app = express();
app.use(express.json());
app.get("/", (req, res) => {
res.status(200).json({
status: "success",
message: "Ohh You come across the right place!",
});
});
app.use("/api/", userRouter);
app.use("/api/", postRouter);
app.use("/api/", commentRouter);
app.all("*", (req, res, next) => {
next(
new AppError(
`The requested ${req.originalUrl} not exist on this server!`,
404
)
);
});
app.use(globalErrorHandler);
export default app;