-
Notifications
You must be signed in to change notification settings - Fork 1
/
useraddress.js
47 lines (45 loc) · 1.27 KB
/
useraddress.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
var https = require('https'),
fs = require('fs'),
sockjs = require('sockjs'),
search = require('./search'),
config = require('./config');
var sockServer = sockjs.createServer();
sockServer.on('connection', function(conn) {
var searchSession = search.getSession();
searchSession.on('row', function(row) {
row.type='row';
console.log(row);
conn.write(JSON.stringify(row));
});
searchSession.on('status', function(status) {
console.log(status);
conn.write(JSON.stringify({
type: 'status',
status: status
}));
});
conn.on('data', function(message) {
console.log(message.toString());
searchSession.search(message.toString());
});
conn.on('close', function() {
searchSession.close();
});
});
var server = https.createServer(config.https, function (req, res) {
console.log(req.url);
if(req.url == '/sockjs-0.3.min.js') {
fileName = 'sockjs-0.3.min.js';
} else if(req.url.substring(0,5)=='/demo') {
fileName = 'demo.html';
} else {
fileName = 'index.html';
}
console.log(fileName);
fs.readFile(fileName, function(err, data) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end(data);
});
}).listen(12380);
sockServer.installHandlers(server, {prefix:'/q'});
console.log('Server running');