-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathapp.js
33 lines (27 loc) · 988 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
require("dotenv").config();
const express = require("express");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const cors = require("cors");
const adminRoutes = require("./routes/admin");
const app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(cors());
const path = require("path");
app.set("view engine", "ejs");
app.set("views", "views");
app.use(express.static(path.join(__dirname, "client", "build")));
app.use("/api", adminRoutes);
app.use("/*", (req, res, next) => {
res.sendFile(path.join(__dirname, "client", "build", "index.html"));
});
mongoose
.connect(process.env.MONGO_URI, { useNewUrlParser: true, useUnifiedTopology: true })
.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));