-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathserver.js
54 lines (42 loc) · 1.36 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
const express = require("express");
const bodyParser = require("body-parser");
const { default: mongoose } = require("mongoose");
const categoryRoute = require("./routes/catgeory-route");
const unitOfMeasureRoute = require("./routes/unitOfmeasure-route");
const productRoute = require("./routes/product-route");
const userRoute = require("./routes/user-route");
const cartRoute = require("./routes/cart-route");
let dotenv = require("dotenv").config();
const app = express();
app.use((req, res, next) => {
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept, Authorization"
);
res.setHeader(
"Access-Control-Allow-Methods",
"GET, POST, PUT, PATCH, DELETE"
);
next();
});
app.use(bodyParser.json());
app.use('/uploads', express.static('uploads'));
app.use("/category", categoryRoute);
app.use("/unit", unitOfMeasureRoute);
app.use("/product", productRoute);
app.use("/user", userRoute);
app.use("/cart", cartRoute);
app.get("/", async (req, res) => {
return res.status(404).json({ message: "Error page not Found 404" });
});
mongoose
.connect(process.env.MONGOPATH)
.then(() => {
console.log("Connect to Database...");
app.listen(5500);
console.log("listening in port 5500");
})
.catch((err) => {
console.log(err.message);
});