-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
39 lines (32 loc) · 838 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
36
37
38
39
const express = require("express");
const userRouter = require("./routes/user");
const taskRouter = require("./routes/task");
const dotenv = require("dotenv");
const app = express();
const cors = require("cors");
const cookieParser = require("cookie-parser");
const { errorMiddleware } = require("./middlewares/error");
const { config } = dotenv;
app.use(cors());
config({
path: "./data/config.env",
});
// middlewares
app.use(express.json());
app.use(cookieParser());
app.use(
cors({
origin: [process.env.FRONTEND_URL],
methods: ["POST", "GET", "PUT", "DELETE"],
credentials: true,
})
);
// using routes
app.use("/api/v1/users", userRouter);
app.use("/api/v1/task", taskRouter);
app.get("/", (req, res) => {
return res.send("Hi abhi man");
});
// error Handling
app.use(errorMiddleware);
module.exports = app;