-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
42 lines (35 loc) · 951 Bytes
/
server.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
import express from "express";
import cors from "cors";
import dotenv from "dotenv";
dotenv.config();
import connectDB from "./config/db.js";
import userRoutes from "./routes/userRoutes.js";
import cookieParser from "cookie-parser";
import wallRoutes from "./routes/wallRoutes.js";
import { notFound, errorHandler } from "./middleware/errorMiddleware.js";
connectDB();
const port = process.env.PORT;
const app = express();
// body parser middleware
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
//fix cors issue
app.use(
cors({
origin: "*",
})
);
//cookie parse middleware
app.use(cookieParser());
// routes
app.use("/api/users", userRoutes);
app.use("/api/wallhaven", wallRoutes);
app.get("/", (req, res) => {
res.send("Hello This is HeavenWalls API");
});
//custom error middleware
app.use(notFound);
app.use(errorHandler);
app.listen(port, () => {
console.log(`Server Running on Port - ${port}`);
});