forked from mohit355/maoBackend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
49 lines (36 loc) · 1.2 KB
/
index.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
require("dotenv").config();
const express = require("express");
const cors = require("cors");
const path = require("path");
const bodyParser = require("body-parser");
const morgan = require("morgan");
// import routes
const authRoutes = require("./routes/auth");
const addressRoutes = require("./routes/address");
const productRoutes = require("./routes/product");
const orderRoutes = require("./routes/order");
const discountRoutes = require("./routes/discount");
const app = express();
// routes middleware
app.use(express.json())
app.use(bodyParser.json());
app.use(morgan("dev"));
app.use(cors({ origin: "*", credentials: true }));
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Credentials", true);
res.header("Access-Control-Allow-Methods", "GET,PUT,POST,DELETE");
res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept"
);
next();
});
app.use("/api", authRoutes);
app.use("/api", addressRoutes);
app.use("/api", productRoutes);
app.use("/api", orderRoutes);
app.use("/api", discountRoutes);
app.listen(process.env.PORT ,()=>{
console.log(`Server started at port ${process.env.PORT} `)
})