-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker.js
executable file
·45 lines (33 loc) · 988 Bytes
/
worker.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
'use strict';
module.exports = function (port) {
let express = require('express'),
express_logger = require('morgan'),
coolog = require('coolog'),
path = require('path');
let statics = express.static;
let api = require('./api')();
let app = express();
let server = require('http').Server(app);
let io = require('socket.io')(server);
coolog.addChannel({
name: 'root',
level: 'debug',
appenders: ['console']
});
let logger = coolog.logger(path.basename(__filename));
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express_logger('dev'));
app.use(statics(__dirname + '/public'));
// API
app.get('/init/:user', api.init);
server.listen(port, function() {
logger.info('listen on ', port);
});
io.on('connection', function (socket) {
socket.on('addEvent', function(data) {
socket.broadcast.emit('addEvent', data);
logger.info('resending', data);
});
});
};