-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
133 lines (102 loc) · 4.55 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/* Some initialization boilerplate. Also, we include the code from
routes/routes.js, so we can have access to the routes. Note that
we get back the object that is defined at the end of routes.js,
and that we use the fields of that object (e.g., routes.get_main)
to access the routes. */
var express = require('express');
var routes = require('./routes/routes.js');
var chats = require('./routes/chatRoutes.js');
var app = express();
app.use(express.urlencoded());
var http = require('http').Server(app);
var io = require('socket.io')(http);
var session = require('express-session');
app.use(session({
secret: 'loginSecret',
resave: false,
saveUnitialized: true,
cookie: { secure: false }
}));
io.on("connection", function (socket) {
console.log("connected!");
socket.on("chat message", function (obj) {
console.log("chat message");
console.log(obj);
if (obj.room == undefined) {
console.log("null room");
}
else {
console.log(obj.room);
io.sockets.in(obj.room).emit("chat message", obj);
console.log("emitted");
}
});
socket.on("join room", function (obj) {
console.log("join");
console.log(obj.room);
socket.join(obj.room);
});
socket.on("leave room", function (obj) {
console.log("leave");
console.log(obj.room)
socket.leave(obj.room);
});
});
/* Below we install the routes. The first argument is the URL that we
are routing, and the second argument is the handler function that
should be invoked when someone opens that URL. Note the difference
between app.get and app.post; normal web requests are GETs, but
POST is often used when submitting web forms ('method="post"'). */
app.get('/', routes.get_main);
app.get('/signup', routes.get_signup);
app.get('/logout', routes.get_logout);
app.get('/chat', routes.get_chat);
app.get('/wall', routes.get_wall);
app.get('/otherwall', routes.get_otherwall);
app.get('/edit', routes.get_edit);
app.get('/news', routes.get_news);
app.get('/newsSearch', routes.get_news_search);
app.get('/getCreator', routes.get_creator);
//NEW
app.get('/homepage', routes.get_homepage);
app.get('/getPostAjax', routes.get_homepagePostListAjax);
app.get('/getWallAjax', routes.get_wallListAjax);
app.get('/getEditUserInfoAjax', routes.get_editUserInfoAjax);
app.get('/getAllUsername', routes.get_allUsername);
app.post('/createpost', routes.post_newPostAjax);
app.post('/createcomment', routes.post_newCommentAjax);
app.post('/createwall', routes.post_newWallAjax);
app.post('/postUpdateUser', routes.post_updateUser);
app.post('/addLikesToPost', routes.post_addLikesToPost);
app.post('/checklogin', routes.verifyUser);
app.get('/getIsWallAFriend', routes.get_isWallAFriend);
app.post('/sendFriendRequest', routes.send_friend_request);
app.post('/rejectFriendRequest', routes.reject_friend_request);
app.post('/acceptFriendRequest', routes.accept_friend_request);
app.post('/createaccount', routes.post_newAccount);
app.post('/editaccount', routes.post_updateUser);
app.post('/postOtherWallPageAjax', routes.post_otherWallPageAjax);
app.get('/getDetermineWallOwner', routes.get_determineWallOwner),
app.get('/getUserInfo', routes.get_userInfo),
//chat
app.get('/getonlineusers', chats.get_online_users);
app.get('/getchat', chats.get_chat);
app.post('/addchatroom', chats.add_chatroom);
app.post('/addonlineuser', chats.add_online_user);
app.post('/addonlineuser', chats.add_online_user);
app.post('/addmessage', chats.add_message);
app.get('/getchatrooms', chats.get_chatrooms);
app.post('/logoutchat', chats.log_out);
app.post('/inviteuser', chats.invite_user);
app.post('/rejectinvite', chats.reject_invite);
app.post('/acceptinvite', chats.accept_invite);
app.get('/chatlogout', chats.log_out);
//visualizer
app.get('/visualizer', routes.get_friend_visualizer);
/* Run the server */
console.log('Author: Jiwoong Matt Park (mtp0326)');
// app.listen(8080);
http.listen(8080, () => {
console.log('listening on 8080');
});
console.log('HTTP server started on port 8080');