-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
57 lines (48 loc) · 1.77 KB
/
index.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
const express = require('express');
const Rooms = require('./Session/Rooms');
const app = express();
const http = require('http').Server(app);
const io = require('socket.io')(http);
const Passwords = require('./Session/Passwords');
const getStore = require('./Store/Store');
app.use(express.static('static'));
const rooms = new Rooms(io);
const pass = new Passwords();
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
app.get('/createPassword', (req, res) => {
const sessionId = req.query.sessionId;
const password = pass.createPassword(sessionId);
res.json({ password });
});
app.get('/getSessionIdFromPassword', (req, res) => {
const password = req.query.pass;
const sessionId = pass.getSessionId(password);
if (sessionId) {
res.json({ sessionId });
} else {
res.json({ sessionId: false });
}
});
app.get('/createNewRoom', (req, res) => {
const isResetButtonMasterOnly = req.query.isResetButtonMasterOnly === 'true';
const isSoundButtonMasterOnly = req.query.isSoundButtonMasterOnly === 'true';
const isSimpleBackground = req.query.isSimpleBackground === 'true';
const roomId = rooms.createNewRoom({ isResetButtonMasterOnly, isSoundButtonMasterOnly, isSimpleBackground });
res.redirect(`/session.html?sessionId=${roomId}`);
});
const serverOpenDate = new Date().toString();
app.get('/analytics', (req, res) => {
const store = getStore();
res.json({
roomCount: rooms.rooms.length,
openDate: serverOpenDate,
...store.data()
});
});
const SERVER_PORT = process.env.PORT ?? 80;
http.listen(SERVER_PORT);
console.log('Server listening on ' + SERVER_PORT);