-
Notifications
You must be signed in to change notification settings - Fork 16
/
server.js
53 lines (47 loc) · 1.7 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
const express = require("express");
const app = express();
const bodyParser = require("body-parser");
const cors = require("cors");
const mongoose = require("mongoose");
const loginRoute = require("./routes/login_route");
const classRoutes = require("./routes/class_management_routes");
const homeworkRoutes = require("./routes/homework_routes");
const dfRoutes = require("./routes/df/df_routes");
const mRoutes = require("./routes/m/m_routes");
const relRoutes = require("./routes/rel/rel_routes");
const io = require("socket.io");
const configs = require('./config/config');
const socketEvents = require("./utils/socket_events");
const constants = require("./utils/constants");
const busboy = require('connect-busboy'); //middleware for form/file upload
const path = require('path'); //used for file path
app.use(busboy());
app.use(express.static(path.join(__dirname, 'public')));
const server = app.listen(configs.BACKEND_PORT, function () {
console.log("Student management system backend server is running on port : " + configs.BACKEND_PORT);
});
const socketServer = io(server);
mongoose
.connect(
configs.MONGO_URI + "/" + constants.MONGO_DB_NAME,
{useNewUrlParser: true}
)
.then(() => {
console.log("MongoDB database connection established successfully");
})
.catch(err => {
console.log(err.message);
});
// Middleware
app.use(cors());
app.use(bodyParser.json());
app.use("/login", loginRoute);
app.use("/class", classRoutes);
app.use("/homework", homeworkRoutes);
app.use("/df", dfRoutes);
app.use("/m", mRoutes);
app.use("/rel", relRoutes);
// Sockets
socketServer.on(socketEvents.CONNECT, async (socket) => {
require('./sockets/chatMessage')(io, socket);
});