-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
55 lines (45 loc) · 1.37 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
const express = require("express");
const dotenv = require("dotenv");
const colors = require("colors");
const morgan = require("morgan");
const mongoSanitizer = require("express-mongo-sanitize");
const xss = require("xss-clean");
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();
//middlewares
app.use(express.json());
app.use(cors());
app.use(morgan("dev"));
//Data Sanitization against NoSQL query injection
app.use(mongoSanitizer());
//Data Sanitization against site script XSS
app.use(xss());
//routes
// 1 test route
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 Folder
app.use(express.static(path.join(__dirname, "./client/build")));
//Static Route
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} ModeOn Port ${process.env.PORT}`
.bgBlue.white
);
});