-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
51 lines (40 loc) · 1.07 KB
/
app.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
const express = require("express");
const bodyParser = require("body-parser");
const path = require("path");
const app = express();
const mongoose = require("mongoose");
const cors = require("cors");
require("dotenv/config");
app.use(express.static(path.join(__dirname, "build")));
app.use(cors());
//convert data to json
app.use(express.json());
app.use(
express.urlencoded({
extended: true,
})
);
mongoose.pluralize(null);
//import routers
const liftRoute = require("./routes/liften");
const liftHistoryRoute = require("./routes/liftHistory");
//use routers
app.use("/api/liften", liftRoute);
app.use("/api/liftenhistory", liftHistoryRoute);
//react routing
app.use(express.static(path.join(__dirname, "build")));
app.get("/*", function (req, res) {
res.sendFile(path.join(__dirname, "build", "index.html"));
});
connectDb();
async function connectDb() {
try {
await mongoose.connect(process.env.DB_CONNECTION, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
} catch (error) {
console.log(error);
}
}
app.listen(process.env.PORT || 8080);