-
Notifications
You must be signed in to change notification settings - Fork 1
/
Server.js
143 lines (112 loc) · 3.91 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
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
141
142
143
var express = require('express');
var app = express();
const querystring = require('querystring');
const START_MONEY_AMOUNT = 100;
//const decodeUriComponentExt = require('decodeuricomponent');
//app.set('view engine', 'ejs');
app.use(express.static('Public'));
//app.use(express.static('javascript/ClientSide'));
//app.use(express.static('css'));
//app.use(express.static('html'));
var expressValidator = require('express-validator');
app.use(expressValidator());
var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
var methodOverride = require('method-override');
app.use(methodOverride(function (req, res) {
console.log(req.query)
if (req.body && typeof req.body === 'object' && '_method' in req.body) {
var method = req.body._method;
delete req.body._method;
return method
}
}));
var flash = require('express-flash');
var cookieParser = require('cookie-parser');
var session = require('express-session');
app.use(cookieParser('csci3308'));
app.use(session({
secret: 'csci3308',
resave: false,
saveUninitialized: true,
cookie: {maxAge: 60000}
}));
app.use(flash());
/*
var index = require('./routes/index');
var store = require('./routes/store');
app.use('/', index);
app.use('/store', store);
*/
/*
app.get('/CreateAccount', function(req, res){
// Validate user input
req.assert('username', 'Username is required').notEmpty();
//req.assert('email', 'Email is required').notEmpty();
req.assert('password', 'Password is required').notEmpty();
var errors = req.validationErrors();
if(!errors){
var cleaned = {
username: req.sanitize('username').escape().trim(),
//email : req.sanitize('email').escape().trim(),
password: req.sanitize('password').escape().trim()
};
// Need a way to check if username already exists
// Need a way to validate password
var query = 'insert into users(username, email, password, funds) values($1, $2, $3, $4);';
db.none(query, [cleaned.username, 'cleaned.email', cleaned.password, START_MONEY_AMOUNT])
.then(function(result) {
req.flash('success', 'Your account has been created successfully!');
//response.render()
}).catch(function (err) {
req.flash('error', err);
//response.render()
})
}else{
console.log('error!!');
var error_msg = errors.reduce((accumulator, current_error)=> accumulator + '<br />' + current_error.msg, '');
req.flash('error', error_msg);
console.log(error_msg);
//response.render()
}
});*/
app.get('/test', function (req, res){
//console.log('yeet');
var j = {
message:"hi",
value:20
};
res.status(200)
.json(j)
.end;
});
var PageHandler = require('./PageHandler');
var CreateAccount = require('./routes/accounts');
var CreateGroup = require('./routes/CreateGroup');
var JoinGroup = require('./routes/JoinGroup');
var Login = require('./routes/Login');
var GetGroups = require('./routes/GetGroups');
var GetGames = require('./routes/GetGames');
var GetUserData = require('./routes/GetUserData');
var UpdateUser = require('./routes/UpdateUser');
var MakeBet = require('./routes/MakeBet');
var GetGroupUsers = require('./routes/GetGroupUsers');
app.use('/', PageHandler);
app.use('/CreateAccount', CreateAccount);
app.use('/CreateGroup', CreateGroup);
app.use('/JoinGroup', JoinGroup);
app.use('/Login', Login);
app.use('/GetGroups', GetGroups);
app.use('/GetGames', GetGames);
app.use('/GetUserData', GetUserData);
app.use('/UpdateUser', UpdateUser);
app.use('/MakeBet', MakeBet);
app.use('/GetGroupUsers', GetGroupUsers);
let port = process.env.PORT;
if (port == null || port == "") {
port = 5000;
}
app.listen(port, function () {
console.log('Server running on http://localhost:' + port)
});