forked from harsh2201/CryptX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
56 lines (44 loc) · 1.16 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
const express = require("express");
const app = express();
const bodyParser = require("body-parser");
const mongoose = require("mongoose");
const cors = require("cors");
const path = require("path");
const dotenv = require("dotenv");
//Requiring routes
const authUser = require("./routes/auth");
const level = require("./routes/levels");
dotenv.config();
const db = process.env.MONGO_URI;
mongoose
.connect(db, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true
})
.then(() => console.log("Database connected"))
.catch(err => {
console.log(err);
});
app.use(
express.urlencoded({
extended: false
})
);
app.use(bodyParser.json());
app.use(cors());
app.use("/user", authUser);
app.use("/", level);
app.use("/public", express.static("public"));
if (process.env.NODE_ENV === "production") {
// Set static folder
app.use(express.static("client/build"));
app.use("/public", express.static("public"));
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname, "client", "build", "index.html"));
});
}
const PORT = process.env.PORT || 5000;
var server = app.listen(PORT, () => {
console.log(`Server started on ${PORT}`);
});