-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
30 lines (22 loc) · 732 Bytes
/
index.js
File metadata and controls
30 lines (22 loc) · 732 Bytes
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
const express = require("express");
const app = express();
const cors = require("cors");
const path = require("path");
const bodyParser = require("body-parser");
//connect to mongodb via mongoose
const db = require("./db");
//Middleware
app.use(bodyParser.json());
app.use(cors());
//Routing API
const bodydata = require("./routes/api/bodyData");
app.use("/api/bodyData", bodydata);
if (app.get("env") === "production") {
//set static folder for react
app.use(express.static("client/build"));
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname, "client", "build", "index.html"));
});
}
const port = process.env.PORT || 4545;
app.listen(port, () => console.log(`Server listening on port ${port}`));