-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.js
35 lines (29 loc) · 991 Bytes
/
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
require("dotenv").config();
const express = require("express");
const bodyParser = require("body-parser");
const cors = require("cors");
const mongoose = require("mongoose");
const path = require("path");
const app = express();
const messageRoutes = require("./routes/message");
const adminRoutes = require("./routes/admin");
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(cors());
app.use(express.static(path.join(__dirname, "client", "build")));
app.use("/api/admin", adminRoutes);
app.use("/api", messageRoutes);
if (process.env.NODE_ENV === "production") {
app.use("/*", (req, res, next) => {
res.sendFile(path.join(__dirname, "client", "build", "index.html"));
});
}
mongoose
.connect(process.env.MONGO_URI)
.then((result) => {
console.log("Connected to MongoDB");
app.listen(process.env.PORT, () => {
console.log(`Server Listening on Port ${process.env.PORT}`);
});
})
.catch((err) => console.log(err));