-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathindex.js
More file actions
55 lines (50 loc) · 1.51 KB
/
Copy pathindex.js
File metadata and controls
55 lines (50 loc) · 1.51 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
const express = require('express');
require('dotenv').config();
const bodyParser = require('body-parser');
const path = require('path');
const db = require('./dbTools');
const auth = require('./auth');
const app = express();
app.use(express.static(path.join(__dirname, '/public')));
app.use(bodyParser.urlencoded({
extended: true,
}));
app.use(bodyParser.json());
const port = process.env.PORT || 5000;
app.set('port', port);
const server = app.listen(port, '0.0.0.0', (err) => {
if (err) {
console.log(err);
} else {
console.log('listening on port', port);
}
});
// let users = 0;
// const io = require('socket.io')(server);
const io = require('socket.io')(server);
io.on('connection', (socket) => {
console.log('connected');
socket.on('room', function(data) {
console.log('in joining room in SERVER', data)
let room = 'alpha';
// socket.join(room)
socket.emit('new user join', ['user']);
// setTimeout(() => {
// socket.in('alpha').emit('new user join', data.user)
// }, 2000);
});
});
app.post('/signin', (req, res) => {
auth.tokenCheck(req.body.idtoken, (gUserData) => {
db.findUser(gUserData, (bcUserProfile) => {
res.status(200).send(bcUserProfile);
});
});
});
app.get('/competitions', db.getChallenges);
app.get('/competition', db.getChallengeById);
app.post('/uniquecompetition', db.returnOneChallenge);
app.post('/makechallenge', db.makeChallenge);
app.post('/gamewin', db.gameWin);
app.get('/games', db.getGameWinners);
app.get('/findUserById', db.findUserById);