-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
55 lines (33 loc) · 1.36 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
44
45
46
47
48
49
50
51
52
53
54
55
import express from "express";
import userRouter from "./routes/user.js";
import taskRouter from "./routes/task.js";
import { config } from "dotenv"
import cookieParser from "cookie-parser";
import { errorMiddleware } from "./middlewares/error.js";
// backend or frontend ka url alalg alag hota hai esliye cors import keya
import cors from "cors";
export const app = express();
config({
path:"./data/config.env",
});
//------------------middle ware-------------------------------------------------//
app.use(express.json()); // to send json data
app.use(cookieParser());
app.use(cors({
origin: [process.env.FRONTEND_URL],
methods:["GET","POST" , "PUT" , "DELETE"],
credentials: true,
}))
// -----------------------------------------------------------------------------//
// ------------------------------------------------------------------------------------------------//
app.use("/api/v1/users",userRouter);
app.use("/api/v1/task",taskRouter);
// ------------------------------------------------------------------------------------------------//
app.get("/" , (req,res)=>(
res.send("Shree Hare Radhe")
))
// --------error handler------------------------------
// jun hum kese function me next ko call krenge while passing error to sara program band ho jayega
// or ye wala error handler chelaga
// using error middleware
app.use(errorMiddleware)