-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.js
45 lines (35 loc) · 1.14 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
const express = require('express');
const app = express();
const technoDoc = require('techno-gendoc');
const path = require('path');
let expressWs = require('express-ws')(app);
const emailObj = {};
['/', '/login', '/register', '/scoreboard', '/user', '/game', '/menu'].forEach((path) => { app.use(path, express.static('public')); });
app.use(express.static('public'));
app.ws('/ws/field', (ws, req) => {
console.log('Generate field');
let randomArray = (length, max) => [...new Array(length)]
.map((_, i) => Math.round(Math.random() * max));
ws.on('message', (msg) => {
try {
let message = {
type: 'field',
data: 'Dorofeev Dmitry Anatholich',
};
ws.send(JSON.stringify(message));
} catch (err) {
console.error(err);
}
});
ws.on('close', (evt) => {
console.log('EXIT');
});
// try {
// ws.send(JSON.stringify(message));
// } catch (err) {
// console.error(err);
// }
});
app.listen(process.env.PORT || 3000, () => {
console.log(`App started on port ${process.env.PORT || 3000}`);
});