-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
79 lines (69 loc) · 2.39 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const { connect } = require("./DBsql/DB");
var express = require("express"),
app = express(),
bodyParser = require("body-parser"),
http = require("http").createServer(app),
io = require("socket.io")(http),
//localStrategy = require("passport-local"),
expressSession = require("express-session"),
methodOverride = require("method-override"),
path = require("path"),
//route = "",
//refe = "",
//rout = "",
flash = require("connect-flash"),
con = require("./DBsql/DB"),
UserRoute = require("./routes/user.js"),
StudentRoute = require("./routes/student"),
CoursesRoute = require("./routes/courses");
app.use(flash());
app.use(methodOverride("_method"));
app.use(expressSession({
secret: "mklvjhndasha",
resave: false,
saveUninitialized: false
}));
app.use(function (req, res, next) { // Locals
// req.headers.referrer || req.headers.referer
// req.get('Referrer') // They both work
res.locals.messages = req.flash("success");
res.locals.errors = req.flash("error");
next();
});
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(UserRoute);
app.use(StudentRoute);
app.use("/courses/", CoursesRoute);
app.use(express.static("assets"));
app.set("view engine", "ejs");
app.set("views", path.join(__dirname, "views"));
http.listen(2305, function () {
console.log("Server has started on port 2305".toUpperCase());
io.on("connection", function (socket) {
socket.on("searchOfcourses", function (course) {
if (course) {
con.query("CALL SearchAllCourses(?)", [course], function (err, result) {
socket.emit("coursesSearched", result[0]);
});
}
else {
con.query("SELECT * FROM courses", function (err, result) {
socket.emit("coursesSearched", result);
});
}
});
socket.on("AddFollow", function(r) {
con.query("INSERT INTO s_takes_c VALUES ('" + r.CourseID + "', '" + r.UserID + "')", function(err, result) {
})
});
socket.on("DeleteFollow", function(r) {
con.query("DELETE FROM s_takes_c WHERE CourseID='" + r.CourseID + "' AND StudentID='" + r.UserID + "'", function(err, result) {
})
});
/*socket.on("Refer", function(ref) {
refe = ref;
});*/
});
});