-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
34 lines (29 loc) · 961 Bytes
/
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
const express = require("express");
const app = express();
const mongoose = require("mongoose");
const { PORT } = require("./config");
const cors = require("cors");
const morgan = require("morgan");
const bodyParser = require("body-parser");
const UserProfileRoutes = require("./routes/api/userProfiles");
const path = require("path");
app.use(cors());
app.use(morgan("tiny"));
app.use(bodyParser.json());
mongoose
.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => console.log("MongoDB database Connected..."))
.catch((err) => console.log(err));
app.use("/api/userProfiles", UserProfileRoutes);
if (process.env.NODE_ENV === "production") {
app.use(express.static("client/dist"));
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname, "client", "dist", "index.html"));
});
}
app.listen(PORT, "0.0.0.0", () =>
console.log(`App listening at http://localhost:${PORT}`)
);