-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
63 lines (57 loc) · 2.06 KB
/
server.js
File metadata and controls
63 lines (57 loc) · 2.06 KB
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
var app = require('http').createServer(handler)
, io = require('socket.io').listen(app)
, fs = require('fs')
app.listen(1337);
function handler (req, res) {
fs.readFile(__dirname + '/index.html',
function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading index.html');
}
res.writeHead(200);
res.end(data);
});
}
io.sockets.on('connection', function (socket) {
socket.on('message', function (data) {
var data = JSON.parse(data)
var packet = {
request: {
path: '/some/url',
metadata: {
request_id: data.params.metadata.request_id,
http_over_websocket_token: data.params.metadata.http_over_websocket_token
}
},
response: {
status: '200',
statusText: 'OK',
body: {'for': 'example', 'key': 'value'
// temporary
, 'name': data.params.data,'data': data.params.metadata.request_id
},
headers: {
// temporary
"Date": "Mon, 29 Jul 2013 16:45:32 GMT",
"Content-Encoding": "gzip",
"X-Content-Type-Options": "nosniff",
"Last-Modified": "Sun, 28 Jul 2013 22:49:14 GMT",
"Server": "GSE",
"ETag": "fdf40d69-b313-4950-9b63-89def9e98125",
"Content-Type": "text/html; charset=UTF-8",
"Cache-Control": "private, max-age=0",
"Content-Length": "31942",
"X-XSS-Protection": "1; mode=block",
"Expires": "Mon, 29 Jul 2013 16:45:32 GMT"
}
}
}
socket.packet({
type: 'message',
data: JSON.stringify(packet)
})
});
});
var connect = require('connect');
connect.createServer(connect.static(__dirname)).listen(1336);