aa69de6c by Glitch (hello-express)

:clap::sweet_potato: Checkpoint

./server.js:13690106/661
1 parent 2d588134
1 {"jack\u001bname":{"":{":":"Jack",">":1586991774902}}}
...\ No newline at end of file ...\ No newline at end of file
1 {"!":{"":1}}
...\ No newline at end of file ...\ No newline at end of file
...@@ -6,9 +6,9 @@ var server = http.createServer().listen(3000); ...@@ -6,9 +6,9 @@ var server = http.createServer().listen(3000);
6 6
7 // LRU with last used sockets 7 // LRU with last used sockets
8 const QuickLRU = require('quick-lru'); 8 const QuickLRU = require('quick-lru');
9 const lru = new QuickLRU({maxSize: 100}); 9 const lru = new QuickLRU({maxSize: 1});
10 10
11 var wss_event = new WebSocket.Server({ noServer: true}); 11 //var wss_event = new WebSocket.Server({ noServer: true});
12 12
13 server.on('upgrade', async function (request, socket, head) { 13 server.on('upgrade', async function (request, socket, head) {
14 var pathname = url.parse(request.url).pathname || '/gun'; 14 var pathname = url.parse(request.url).pathname || '/gun';
...@@ -22,15 +22,20 @@ server.on('upgrade', async function (request, socket, head) { ...@@ -22,15 +22,20 @@ server.on('upgrade', async function (request, socket, head) {
22 } else { 22 } else {
23 // Create Node 23 // Create Node
24 console.log('Create id',pathname); 24 console.log('Create id',pathname);
25 gun = await Gun({peers:[], ws: { path: pathname}, web: new WebSocket.Server({ noServer: true})}); 25 var wserver = new WebSocket.Server({ noServer: true});
26 gun = new Gun({peers:[], ws: { path: pathname}, web: server });
26 lru.set(pathname,gun); 27 lru.set(pathname,gun);
27 } 28 }
28 } 29 }
29 if (gun){ 30 if (gun){
30 // Handle Request 31 // Handle Request
31 gun.handleUpgrade(request, socket, head, function (ws) { 32 console.log('handle connection...');
32 gun.emit('connection', ws); 33 //ws.emit('connection', socket);
34 wserver.handleUpgrade(request, socket, head, function (ws) {
35 console.log('connecting.. ')
36 ws.emit('connection', socket);
33 }); 37 });
38
34 } else { 39 } else {
35 socket.destroy(); 40 socket.destroy();
36 } 41 }
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!