-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
64 lines (56 loc) · 1.6 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const express = require("express");
const bodyParser = require("body-parser");
const mongoose = require("mongoose");
const cors = require("cors");
const keys = require("./config/keys");
const app = express();
const PORT = process.env.PORT || 5000;
const { setPrimeVendor, setSCoin } = require("./helpers/primeVendorSeed");
const authRoutes = require("./routes/authRoutes");
const orderRoutes = require("./routes/orderRoutes");
const adminRoutes = require("./routes/adminRoutes");
const callBackRoutes = require("./routes/callBackRoutes");
const userRoutes = require("./routes/userRoutes");
app.use(bodyParser.json());
app.use(
bodyParser.urlencoded({
extended: true
})
);
app.use(express.static(__dirname + "/client"));
app.use(cors());
app.use("/auth", authRoutes);
app.use("/order", orderRoutes);
app.use("/admin", adminRoutes);
app.use("/callback", callBackRoutes);
app.use("/user", userRoutes);
app.get("/", (req, res, next) => {
res.sendFile(__dirname + "/client/index.html");
});
app.use((error, req, res, next) => {
if (typeof error === "string") {
error = new Error(error);
}
error.statusCode = error.statusCode || 500;
res.status(error.statusCode).json({
error: true,
message: error.message
});
});
mongoose.set("useCreateIndex", true);
mongoose.connect(keys.DB_URI, { useNewUrlParser: true }, async err => {
if (err) {
throw err;
} else {
console.log("DB Connected");
try {
await setPrimeVendor();
await setSCoin();
app.listen(PORT, () => {
console.log("Server has connected");
});
} catch (error) {
throw error;
}
}
});