-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
53 lines (45 loc) · 1.36 KB
/
app.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
const express = require("express");
const app = express();
const cors = require("cors");
app.use(cors());
const PORT = process.env.PORT || 5000;
const mongoose = require("mongoose");
const { MONGOURL } = require("./config/keys");
//models
require("./models/admin");
require("./models/student");
require("./models/test");
require("./models/message");
require("./models/submitTest");
require("./models/couselling");
require("./models/notice");
require("./models/blogs");
app.use(express.json({ limit: "50mb" }));
app.use("/api", require("./routes/auth"));
app.use("/api", require("./routes/student"));
app.use("/api", require("./routes/test"));
app.use("/api", require("./routes/admin"));
app.use("/api", require("./routes/blogs"));
app.use("/api", require("./routes/notice"));
mongoose.connect(MONGOURL, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
useCreateIndex: true,
});
mongoose.connection.on("connected", () => {
console.log("MongoDB Connected");
});
mongoose.connection.on("error", (err) => {
console.log("Error Connecting", err);
});
if (process.env.NODE_ENV == "production") {
app.use(express.static("client/build"));
const path = require("path");
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname, "client", "build", "index.html"));
});
}
app.listen(PORT, () => {
console.log("Server is running on port ", PORT);
});