-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
39 lines (33 loc) · 991 Bytes
/
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
'use strict'
var express = require('express');
var app = express();
var server = require('http').Server(app);
var http = require('http');
var io = require('socket.io')(server);
var handler = require('./assets/js/handle.js');
var config = require('./config.json');
var port = config.port || 3000;
app.use('/assets', express.static(__dirname + '/assets'));
app.get('/', function(req, res) {
res.sendFile(__dirname + '/pages/index.html', function() {
res.end();
});
});
app.get('/test', function(req, res) {
res.sendFile(__dirname + '/pages/test.html', function() {
res.end();
})
})
server.listen(port, function () {
console.log("Server listening on port", port);
})
io.sockets.on('connection', function(socket) {
let game;
socket.on('start', function(data) {
game = handler(data, null, socket);
})
socket.on('request', function(data) {
if(!game) return;
handler(data, game, socket);
});
});