-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.js
66 lines (51 loc) · 1.92 KB
/
index.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
57
58
59
60
61
62
63
64
65
66
// constants for express routes, paths and db connection
const express = require("express");
const app = express();
const cors = require("cors");
const path = require("path");
const pool = require("./db");
const passport = require("passport");
const multer = require('multer')
const upload = multer({storage: multer.memoryStorage()})
const { parse } = require('./utilities/parser');
const port = process.env.PORT || 5000;
// app connection and resources
app.use(cors());
app.use(express.json());
// models
const Student = require("./models/Student");
const Staff = require("./models/Staff");
const Course = require("./models/Course");
const Career = require("./models/Career");
const Transcript = require("./models/Transcript");
const AdvisingWindow = require("./models/AdvisingWindow");
const ProgrammeCourse = require("./models/ProgrammeCourse");
const CareerCourse = require("./models/CareerCourse");
// if in production (deployment), changes main client path to build
if (process.env.NODE_ENV === "production") {
app.use(express.static(path.join(__dirname, "myadvisor/build")));
}
// routes
app.get("/", (req, res) => {
res.status(200).send("Server running...");
});
app.use("/admin", require("./routes/admin"));
app.use("/student", require("./routes/student"));
app.use("/courses", require("./routes/courses"));
app.use("/careers", require("./routes/careers"));
app.use("/programmes", require("./routes/programmes"));
app.use("/transcript", require("./routes/transcript"));
app.use("/accounts", require("./routes/authorization"));
// if a bad route is entered
if (process.env.NODE_ENV === "production") {
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname, "myadvisor/build/index.html"));
});
} else {
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname, "myadvisor/public/index.html"));
});
}
app.listen(port, () => {
console.log(`Server is starting on port ${port}`);
});