-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
83 lines (48 loc) · 1.62 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
require("dotenv").config();
const express = require("express");
const colors=require("colors");
const ConnectDb = require("./config/db");
const cors=require("cors")
// Import wle syntax me file ka extension bhi dena pdta hai
const authRoutes=require("./routes/auth-routes");
const categoryRoutes=require("./routes/category-route")
const productRoutes=require("./routes/product-routes");
const app=express();
const corsOptions={
origin:"https://e-commerce-front-tawny.vercel.app",
methods:"GET,POST,PUT,DELETE,PATCH,HEAD",
credentials:true,
}
// cors ko btana hai ki 5173 bhi mera hi part hai
// data jaye isliye sbse upar isko state kro
app.use(cors(corsOptions));
// front end with backend
const path = require("path");
app.get("/", (req, res) => {
app.use(express.static(path.join(__dirname, "./Client/dist")));
res.sendFile(path.join(__dirname, "Client/dist/index.html"));
});
// rest object
const morgan =require("morgan");
// middleware
// Morgan is another HTTP request logger middleware for Node. js.
// It simplifies the process of logging requests to your application. Using
// kitne time me load huwa ye sb btat hai production pe koi jrurat nhi hai
app.use(express.json());
app.use(morgan('dev'));
// api(routes)
app.use("/api/v1/auth",authRoutes);
// routes for category
app.use("/api/v1/category",categoryRoutes);
// routes for products
app.use("/api/v1/product",productRoutes);
// port
const port=process.env.PORT;
// run listen
ConnectDb().then(()=>{
app.listen(port,()=>{
console.log(`server running at ${port}`.bgCyan.white);
})}
).catch((e)=>{
console.log("error",e)
})