-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
47 lines (38 loc) · 1.21 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
const express = require("express");
const dotenv = require("dotenv");
const colors = require("colors");
const morgan = require("morgan");
const cors = require("cors");
const connectDB = require("./config/db");
const path = require("path");
//Dot Config
dotenv.config();
//** MongoDb Connection ***/
connectDB();
//***** REST OBJECT ****/
const app = express();
//*** MIDDLEWARE */
app.use(express.json());
app.use(cors());
app.use(morgan("dev"));
//***** MIDDLEWARE ROUTES ****/
app.use("/api/v1/test", require("./routes/testRoutes"));
app.use("/api/v1/auth", require("./routes/authRoutes"));
app.use("/api/v1/inventory", require("./routes/inventoryRoutes"));
app.use("/api/v1/analytics", require("./routes/analyticsRoutes"));
app.use("/api/v1/admin", require("./routes/adminRoutes"));
//STATIC FILES
app.use(express.static(path.join(__dirname, "./client/build")));
//STATIC ROUTES
app.get("*", function (req, res) {
res.sendFile(path.join(__dirname, "./client/build/index.html"));
});
//***** PORT *****/
const PORT = process.env.PORT || 8080;
//***** LISTEN ******/
app.listen(PORT, () => {
console.log(
`Node Server Running In ${process.env.DEV_MODE} mode on Port ${process.env.PORT}`
.bgBlue.white
);
});