-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
52 lines (43 loc) · 1.31 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
import express from "express";
import colors from "colors";
import dotenv from "dotenv";
import morgan from "morgan";
import authRoutes from "./routes/authRoute.js";
import CategoryRoute from "./routes/CategoryRoute.js";
import userRoute from "./routes/UserRoute.js";
import ProductRoute from "./routes/ProductRoute.js";
import cors from "cors";
import bodyParser from "body-parser";
import path from "path";
import connectDB from "./config/db.js";
import { fileURLToPath } from "url";
//configure env
dotenv.config();
//databse config
connectDB();
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const app = express();
app.use(cors());
app.use(express.json());
app.use(morgan("dev"));
app.use(bodyParser.json());
app.use(
bodyParser.urlencoded({
limit: "500mb",
extended: true,
parameterLimit: 1000000,
})
);
app.use("/api/v1/auth", authRoutes);
app.use("/api/v1/user", userRoute);
app.use("/api/v1/category", CategoryRoute);
app.use("/api/v1/product", ProductRoute);
app.use(express.static(path.join(__dirname, "./client/build")));
app.use("*", function (req, res) {
res.sendFile(path.join(__dirname, "./client/build/index.html"));
});
const PORT = process.env.PORT;
app.listen(PORT, () => {
console.log(`Server Running onmode on port ${PORT}`.bgGreen.white);
});