-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
51 lines (44 loc) · 1.92 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
//======================================================
//IMPORT MODULES
//======================================================
const express = require("express"),
app = express(),
path = require("path"),
bodyParser = require("body-parser"),
mongoose = require("mongoose"),
helmet = require("helmet"),
compression = require('compression');
//======================================================
//IMPORT ROUTES
//======================================================
const apiProducts = require("./server/routes/apiProducts"),
apiUser = require("./server/routes/apiUser"),
apiMerchant = require("./server/routes/apiMerchant");
//======================================================
//CONNECT APPJS TO MONGODB DATABASE
//======================================================
mongoose.connect("mongodb://localhost/shopland");
//======================================================
//UTILIZE IMPORTED FUNCTIONS
//======================================================
app.use(helmet());
app.use(compression());
app.use(express.static(path.join(__dirname, "dist")));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:true}));
//======================================================
//PASSPORTJS CONFIGURATION
//======================================================
//======================================================
//UTILIZING ROUTES
//======================================================
app.use("/api/products", apiProducts);
app.use("/api/user", apiUser);
app.use("/api/merchant", apiMerchant);
app.use("*", (req, res) => {
res.sendFile(path.join(__dirname, "dist/index.html"));
});
//======================================================
//INITIATE NODEJS TO START LISTENING REQUEST
//======================================================
app.listen(process.env.PORT, process.env.IP);