-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
92 lines (77 loc) · 2.25 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
var express = require('express');
var path = require('path');
var bodyParser = require('body-parser');
var cors = require('cors');
var app = express();
var path = require('path');
var dir = path.join(__dirname, './uploads');
var node = path.join(__dirname, './node_modules');
var user = require('./api/user.js');
var game = require('./api/game.js');
var port = process.env.PORT || 5200;
app.use(express.static(dir));
app.use(cors());
//app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
var http = require('http').createServer(app);
http.listen(port, function(err) {
if (err) {
return console.log('something bad happened', err)
}
console.log(`server is listening on `+port);
});
//Start Socket
var io = require('socket.io').listen(http);
io.on('connection', function(socket){
console.log("connect"+socket.id);
socket.emit("s_id",socket.id);
socket.on("move",function(data){
console.log("data:"+data);
})
});
//End Socket
//Game module
app.post('/start_game',function(request,response){
game.start_game(request,response);
});
app.post('/get_request',function(request,response){
game.get_request(request,response);
});
app.post('/accept_request',function(request,response){
game.accept_request(request,response,io);
});
app.get('/make_move',function(request,response){
console.log("id:"+request.query.id);
io.to(request.query.id).emit('get_move',request.query.msg);
var status={};
status.status=1;
status.msg="success";
response.send(status);
});
app.get("/home",function(request,response){
var status={};
status.status=1;
status.msg="Welcome to chess";
response.send(status);
});
//Login
app.post("/user_login",function(request,response){
user.user_login(request,response);
});
//Register
app.post("/save_user",function(request,response){
user.save_user(request,response);
});
//Forgot Password
app.post("/forgot_password",function(request,response){
user.forgot_password(request,response);
});
//Change Password
app.post("/change_password",function(request,response){
user.change_password(request,response);
});
//Userlist
app.post("/get_userlist",function(request,response){
user.get_userlist(request,response);
});
module.exports = app;