-
Notifications
You must be signed in to change notification settings - Fork 5
/
server.js
39 lines (33 loc) · 962 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
const express = require("express");
const env = require("dotenv").config();
const bodyParser = require("body-parser");
const cors = require("cors");
const cookieParser = require("cookie-parser");
const router = require("./routers/index");
const {
badRequestHandler,
internalServerErrorHandler,
methodNotAllowedHandler,
notFoundHandler,
} = require("./middleware/error.middleware");
const app = express();
// Add this before your routes
app.use(cookieParser());
app.use(
cors({
origin: "http://localhost:5173",
credentials: true,
})
);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
require("./config/db")();
app.use("/api/v1", router);
//Error Handler Middleware
// app.use(badRequestHandler);
// app.use(internalServerErrorHandler);
// app.use(methodNotAllowedHandler);
// app.use(notFoundHandler);
app.listen(process.env.PORT, function () {
console.log("Server listening on", process.env.PORT);
});