-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
38 lines (29 loc) · 886 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
const fs = require('fs');
// let ngnix know we want to start serving from the proxy
fs.openSync('/tmp/app-initialized', 'w');
const server = require('http').createServer(function (req, res) {
res.writeHead(200);
res.end('hello world');
});
// socket.io setup
const io = require('socket.io').listen(server);
io.set('transports', ['websocket']);
// listen to ngnix socket
server.listen('/tmp/nginx.socket', function () {
console.info(`server up`);
});
io.on('connect_error', function (err) {
console.error(err);
});
io.on('connect_timeout', function (err) {
console.error(err);
});
io.on('connection', function (socket) {
console.info(`socket: ${socket.id} connected`);
socket.on('disconnect', function () {
console.info('disconnected');
});
socket.on('login', message => {
socket.emit('login', {message: message});
})
});