-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
58 lines (45 loc) · 1.94 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const express = require("express");
const app = express();
const mongoose = require("mongoose");
const path = require("path");
const dotenv = require("dotenv");
dotenv.config();
const cors = require("cors");
// local port
const port = process.env.PORT || 4000;
// routes
const submitContent = require("./routes/submitContent");
const getQuestions = require("./routes/getQuestions");
const getInReviewItems = require("./routes/getReviewItems");
const updateReviewItems = require("./routes/updateReviewItems");
const getAllApprovedItems = require("./routes/getAllApproved");
const updateLikes = require("./routes/updateLikes");
const pusherMessage = require("./routes/pusherMessage");
const updateLeaderBoard = require("./routes/updateLeaderBoard");
const getLeaderBoardList = require("./routes/getLeaderBoardList");
// middlewares
app.use(cors());
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use("/submitContent", submitContent);
app.use("/getQuestions", getQuestions);
app.use("/getInReviewItems", getInReviewItems);
app.use("/updateReviewItems", updateReviewItems);
app.use("/getAllApprovedItems", getAllApprovedItems);
app.use("/updateLikes", updateLikes);
app.use("/pusherMessage", pusherMessage);
app.use("/updateLeaderBoard", updateLeaderBoard);
app.use("/getLeaderBoardList", getLeaderBoardList);
// Serve static files assets on heroku
app.use(express.static(path.join(__dirname, "client/build")));
// MongoDB connection strings
const MONGO_LOCAL_URI = `mongodb://localhost:27017/evaluator`;
mongoose
.connect(process.env.NODE_ENV === "production" ? process.env.MONGODB_URI : MONGO_LOCAL_URI)
.then(() => console.log("New Mongodb connection established"))
.catch((err) => console.log("Something went wrong" + err));
// Right before your app.listen(), add this:
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname + "/client/build/index.html"));
});
app.listen(port, () => console.log(`Listening on port ${port}...`));