-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
110 lines (95 loc) · 3.42 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
var http = require('http'),
url = require('url'),
fs = require('fs'),
connectCounter = 0;
var allowedDomain = 'http://liveboard.cafef.vn:*';
var socket_server = http.createServer(function (req, res) {
res.setHeader('Access-Control-Allow-Origin', '*');
var parsedUrl = url.parse(req.url, true);
if (parsedUrl.pathname != '/') {
switch (parsedUrl.pathname) {
case '/intraday-change':
io.sockets.emit('ticker_change', parsedUrl.query.data);
console.log('Data size: ' + Buffer.byteLength(parsedUrl.query.data.toString(), 'utf8') + ' bytes');
res.end('success');
break;
case '/index-change':
io.sockets.emit('index_change', parsedUrl.query.data);
console.log('Data size: ' + Buffer.byteLength(parsedUrl.query.data.toString(), 'utf8') + ' bytes');
res.end('success');
break;
case '/pt-change':
io.sockets.emit('pt_change', parsedUrl.query.data);
console.log('Data size: ' + Buffer.byteLength(parsedUrl.query.data.toString(), 'utf8') + ' bytes');
res.end('success');
break;
case '/user.chn':
res.writeHead(301, {
'Location': '/?userlist=true'
});
res.end();
break;
case '/upcom.chn':
res.writeHead(301, {
'Location': '/?center=9'
});
res.end();
break;
case '/hsx.chn':
res.writeHead(301, {
'Location': '/?center=1'
});
res.end();
break;
case '/hnx.chn':
res.writeHead(301, {
'Location': '/?center=2'
});
res.end();
break;
case '/hnx/thoa-thuan.chn':
res.writeHead(301, {
'Location': '/?center=5'
});
res.end();
break;
case '/hsx/thoa-thuan.chn':
res.writeHead(301, {
'Location': '/?center=3'
});
res.end();
break;
default:
res.writeHead(301, {
'Location': '/'
});
res.end();
}
} else {
fs.readFile('./Default.htm', function (error, content) {
if (error) {
res.writeHead(500);
res.end();
}
else {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(content, 'utf-8');
}
});
}
}).listen(80);
var io = require('socket.io').listen(socket_server);
io.set('log level', 1);
io.enable('browser client minification'); // send minified client
io.enable('browser client etag'); // apply etag caching logic based on version number
io.enable('browser client gzip'); // gzip the file
//io.set('origins', allowedDomain);
io.set('transports', ['jsonp-polling']);
io.sockets.on('connection', function (socket) {
connectCounter++;
console.log('+ Concurrent connection: ' + connectCounter);
socket.on('disconnect', function () {
connectCounter--;
console.log('- Concurrent connection: ' + connectCounter);
});
});