-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
executable file
·56 lines (45 loc) · 1.59 KB
/
Copy pathserver.js
File metadata and controls
executable file
·56 lines (45 loc) · 1.59 KB
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
// Imports
const express = require("express");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const passport = require("passport");
const path = require("path");
// Route Imports
const teams = require("./routes/api/teams");
const challenges = require("./routes/api/challenges");
const submissions = require("./routes/api/submissions");
const notifications = require("./routes/api/notifications");
const gamesettings = require("./routes/api/gamesettings");
// Initialisation
const app = express();
const PORT = process.env.PORT || 8008;
// Body Parser MiddleWare
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
// Connecting to database
const dbURI = require("./config/keys").mongoURI;
const dbOptions = { useNewUrlParser: true };
mongoose
.connect(dbURI, dbOptions)
.then(() => console.log("Database Connected"))
.catch(err => console.log(err));
mongoose.set("useFindAndModify", false);
// Passport Middleware
app.use(passport.initialize());
// Passport confing
require("./config/passport")(passport);
// Use Routes
app.use("/api/teams", teams);
app.use("/api/challenges", challenges);
app.use("/api/submissions", submissions);
app.use("/api/notifications", notifications);
app.use("/api/gamesettings", gamesettings);
// Serve static assets.
if (process.env.NODE_ENV === "production") {
// set a static folder.
app.use(express.static("clientBuild/build"));
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname, "clientBuild", "build", "index.html"));
});
}
app.listen(PORT, () => console.log(`Listening to port ${PORT}`));