-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
43 lines (37 loc) · 1.03 KB
/
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
36
37
38
39
40
41
42
43
import {
AdminRoute,
AuthRoute,
CategoryRoute,
HomeRoute,
PostRoute,
UserRoute,
} from "./routes/index.routes.js";
import DBCONNECT from "./config/dbconnection.js";
import dotenv from "dotenv";
import errorHandler from "./middlewares/ErrorHandler.js";
import express from "express";
import { verifyAccessToken } from "./middlewares/Verifications.js";
import cookieParser from "cookie-parser";
import cors from "cors";
// init dotenv
dotenv.config();
// init app
const app = express();
app.use(cookieParser());
app.use(express.json());
app.use(cors({ credentials: true, origin: true }));
// MIDDLEWARES
app.use("/", HomeRoute);
app.use("/user", verifyAccessToken, UserRoute);
app.use("/admin", verifyAccessToken, AdminRoute);
app.use("/categories", CategoryRoute);
app.use("/posts", PostRoute);
app.use("/auth", AuthRoute);
// ERROR HANDLER MIDDLEWARE
app.use(errorHandler);
// run server
const port = process.env.PORT || 3000;
app.listen(port, async () => {
await DBCONNECT();
console.log(`Server running on port ${port} 🚀`);
});