forked from ishimurataki/HelloWorld
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
140 lines (117 loc) · 5.65 KB
/
app.js
File metadata and controls
140 lines (117 loc) · 5.65 KB
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
134
135
136
137
138
139
140
var express = require('express');
const path = require('path')
var app = express();
//var session = require('express-session');
const http = require('http').createServer(app);
const io = require('socket.io')(http);
const bodyParser = require('body-parser');
const cookieSession = require('cookie-session');
// define/require all schemas here
var schemas = require('./createTableSchemas');
var friendRecFile = './adsorption/out/part-r-00000';
var visualizerView = 'friendvisualizer.ejs';
var User = schemas.User;
var Friend = schemas.Friend;
var Post = schemas.Post;
var Comment = schemas.Comment;
var FriendRequests = schemas.FriendRequests;
var Notification = schemas.Notification;
// define/require all helper dbs here
var friendsDb = require('./db/friendsdb')(Friend, User);
var postsDb = require('./db/postsdb')(Friend, Post);
var usersDb = require('./db/usersdb')(User);
var commentsDb = require('./db/commentsdb')(Comment);
var friendreqDb = require('./db/friendrequestdb')(FriendRequests, User, Friend);
var notificationDb = require('./db/notificationdb')(Notification, Friend);
//define require all routes here
var authRoutes = require('./routes/authroutes.js')(User);
var friendRoutes = require('./routes/friendroutes.js')(friendsDb);
var postRoutes = require('./routes/postroutes.js')(Post, postsDb);
var userRoutes = require('./routes/userroutes.js')(usersDb);
var commentRoutes = require('./routes/commentroutes.js')(commentsDb);
var friendRequestRoutes = require('./routes/friendrequestroutes.js')(friendreqDb);
var notificationRoutes = require('./routes/notificationroutes.js')(notificationDb);
var friendRecRoutes = require('./routes/friendrecroutes.js')(friendRecFile, User, Friend);
var friendVisRoutes = require('./routes/friendvisroutes.js')(User, Friend, visualizerView);
var chatroomRoutes = require('./routes/chatroomroutes');
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(
cookieSession({
maxAge: 30 * 24 * 60 * 60 * 100000,
keys: ['key1', 'key2']
})
);
app.use('/public', express.static('./public/'));
app.use(express.static(path.join(__dirname, 'client/build')))
// friend visualizer
app.get('/friendvisualizer', friendVisRoutes.get_visualizer);
app.get('/friendvisualization', friendVisRoutes.init_visualization);
app.get('/getFriends/:user/:affiliation', friendVisRoutes.get_new_visualization);
// install the routes here
app.post('/api/checklogin', authRoutes.check_login);
app.post('/api/signup', authRoutes.add_user);
app.post('/api/getAllUserInfo', userRoutes.get_all_user_info);
app.post('/api/updateStatus', userRoutes.update_status);
app.post('/api/getStatus', userRoutes.get_status);
app.post('/api/getAllFriends', friendRoutes.get_all_friends);
app.post('/api/getAllOnlineFriends', friendRoutes.get_all_online_friends);
app.post('/api/addFriendship', friendRoutes.add_friendship);
app.post('/api/getAllPosts', postRoutes.get_post);
app.post('/api/addNewPost', postRoutes.add_new_post);
app.post('/api/getAllComments', commentRoutes.get_all_comments);
app.post('/api/addNewComment', commentRoutes.add_new_comment);
app.post('/api/updateProfileAttribute', userRoutes.update_profile_attribute);
app.post('/api/getTopFriendRecommendations', friendRecRoutes.get_top_friend_recs);
app.post('/api/getFriendRecData', friendRecRoutes.get_friend_rec_data);
app.post('/api/getAllNotifications', notificationRoutes.get_all_notifications);
app.post('/api/addNewNotification', notificationRoutes.add_new_notification);
app.post('/api/getAllFriendReqs', friendRequestRoutes.get_all_friend_reqs);
app.post('/api/getAllSentFriendReqs', friendRequestRoutes.get_all_sent_friend_reqs);
app.post('/api/sendFriendRequest', friendRequestRoutes.send_friend_request);
app.post('/api/acceptFriendRequest', friendRequestRoutes.accept_friend_request);
app.post('/api/rejectFriendRequest', friendRequestRoutes.reject_friend_request);
app.get('/api/current_user', authRoutes.get_user);
app.get('/api/logout', authRoutes.remove_user);
app.post('/api/deletePost', postRoutes.delete_post);
app.post('/api/getSentFriendReqs', friendRequestRoutes.get_all_sent_friend_reqs);
app.get('/api/getChatrooms', chatroomRoutes.getChatrooms);
app.post('/api/leaveChatroom', chatroomRoutes.leaveChat);
app.post('/api/viewChat', chatroomRoutes.viewChat);
app.get('*', (req,res) =>{
res.sendFile(path.join(__dirname+'/client/build/index.html'));
});
// run the server below
console.log('Author: Kevin Xu (xukevin)');
app.listen(8080);
console.log('Server running on port. Now open http://localhost:8080/ in your browser!');
// all chat logic is below
const ClientManager = require('./server_socket/ClientManager');
const ChatroomManager = require('./server_socket/ChatroomManager');
const makeHandlers = require('./server_socket/handlers');
const clientManager = ClientManager()
const chatroomManager = ChatroomManager()
io.on('connection', (client) => {
console.log('client connected...', client.id);
// client.on('availableChats', () => {
// io.emit('availableChats', chatroomManager.getAvailableChatrooms())
// })
const {
handleJoin,
handleMessage
} = makeHandlers(client, clientManager, chatroomManager);
clientManager.addClient(client);
client.on('join', handleJoin);
client.on('message', handleMessage);
client.on('error', () => {
console.log('receieved error from client', client.id);
console.log(err);
})
client.on('disconnect', () => {
console.log('user disconnected');
});
// socket.on('chat messsage', handleMessage);
});
http.listen(1024, () => {
console.log('socket is listening on port 1024');
});