-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
56 lines (42 loc) · 1.27 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
// Dependencies
const express = require("express");
const mongoose = require("mongoose");
const cors = require("cors");
// Cors config
const whitelist = ["https://wizards-and-whiteboards.herokuapp.com", "http://localhost:3000"]
const corsOptions = {
origin: whitelist,
credentials: true,
optionSuccessStatus: 200,
methods: "GET, HEAD, POST, PUT"
}
// Environment variables
// Port
const PORT = process.env.PORT || 8080;
// Database
mongoose.connect(process.env.MONGODB_URI || "mongodb://localhost/htmlephant", {
useNewUrlParser: true,
useFindAndModify: false,
useUnifiedTopology: true
});
// Express server instance
const app = express();
// Middleware
app.use(cors(corsOptions));
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
// Routes
const userRoutes = require("./controllers/userController");
app.use(userRoutes);
const npcRoutes = require("./controllers/npcController");
app.use(npcRoutes);
const algoRoutes = require("./controllers/algoController");
app.use(algoRoutes);
// Lovely greeting for anyone who tries to visit the deployed server
app.get("/", (req, res) => {
res.send("Go away, I'm trying to eat my mac and cheese.")
})
// Start server
app.listen(PORT, () => {
console.log(`Listening on port ${PORT}`);
});