-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
44 lines (36 loc) · 1.02 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
/* jshint node: true */
var http = require("http"),
fs = require("fs"),
sockjs = require("sockjs"),
engine = require("engine.io"),
server, engineServer, sockjsServer;
server = http.createServer(function (req, res) {
var path = __dirname + (req.url === '/'? '/index.html': req.url),
stat;
try {
stat = fs.statSync(path);
} catch (e) {
res.writeHead(404);
res.end("Not found.");
return;
}
res.writeHead(200);
fs.createReadStream(path).pipe(res);
});
engineServer = engine.attach(server, {path: "/engine.io"});
engineServer.on('connection', function (socket) {
console.log("eio connected");
socket.on('message', function (data) {
socket.send(data);
});
});
sockjsServer = sockjs.createServer({ sockjs_url: 'http://localhost:7625/sockjs.min.js' });
sockjsServer.on('connection', function (socket) {
console.log("sjs connected");
socket.on('data', function (data) {
socket.write(data);
});
});
sockjsServer.installHandlers(server, {prefix: "/sockjs"});
server.listen(7625);
console.log('http://localhost:7625');