-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
executable file
·48 lines (39 loc) · 1.4 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
const express = require("express"),
cors = require("cors"),
mongoose = require("mongoose");
const path = require("path");
require("dotenv").config();
const app = express();
app.use(cors());
app.use(express.json());
//MONGO ATLAS
const uri = process.env.ATLAS_URI;
mongoose.connect(uri, { useNewUrlParser: true, useUnifiedTopology: true });
const connection = mongoose.connection;
connection.once("open", () =>
console.log("MongoDB database connection established successfully")
);
//SODL
const sodlbestiaryRouter = require("./backend/routes/sodl/bestiary");
//Shadowrun
const shadowrunMissionCreationRouter = require("./backend/routes/shadowrun/missioncreation");
//Roll20
const roll20charsheetsRouter = require("./backend/routes/roll20/charsheets");
//SODL
app.use("/api/ShadowoftheDemonLord/encounter_builder", sodlbestiaryRouter);
//Shadowrun
app.use("/api/Shadowrun/mission_creation", shadowrunMissionCreationRouter);
//Roll20
app.use("/api/Roll20CharSheets", roll20charsheetsRouter);
//Server static assets in production
if (process.env.NODE_ENV === "production") {
app.use(express.static("client/build"));
//Set the static folder
app.get("*", (req, res) =>
res.sendFile(path.resolve(__dirname, "client", "build", "index.html"))
);
} else {
app.use(express.static("client/build"));
}
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => console.log(`Server is running on port: ${PORT}`));