
Checkpoint
./server.js:13690106/434 ./package.json:13690106/1337
Showing
3 changed files
with
28 additions
and
5 deletions
... | @@ -11,7 +11,8 @@ | ... | @@ -11,7 +11,8 @@ |
11 | }, | 11 | }, |
12 | "dependencies": { | 12 | "dependencies": { |
13 | "express": "^4.17.1", | 13 | "express": "^4.17.1", |
14 | "gun": "^0.2020.401" | 14 | "gun": "^0.2020.401", |
15 | "quick-lru": "^5.1.0" | ||
15 | }, | 16 | }, |
16 | "engines": { | 17 | "engines": { |
17 | "node": "12.x" | 18 | "node": "12.x" | ... | ... |
... | @@ -4,17 +4,31 @@ const http = require('http'); | ... | @@ -4,17 +4,31 @@ const http = require('http'); |
4 | const WebSocket = require('ws'); | 4 | const WebSocket = require('ws'); |
5 | var server = http.createServer().listen(3000); | 5 | var server = http.createServer().listen(3000); |
6 | 6 | ||
7 | var gun1 = Gun({peers:[], ws: { noServer: true}}); | ||
8 | var gun2 = Gun({peers:[], ws: { noServer: true}}); | ||
9 | |||
10 | const QuickLRU = require('quick-lru'); | ||
11 | const lru = new QuickLRU({maxSize: 100}); | ||
12 | |||
7 | var wss_event = new WebSocket.Server({ noServer: true}); | 13 | var wss_event = new WebSocket.Server({ noServer: true}); |
8 | 14 | ||
9 | server.on('upgrade', function (request, socket, head) { | 15 | server.on('upgrade', function (request, socket, head) { |
10 | var pathname = url.parse(request.url).pathname; | 16 | var pathname = url.parse(request.url).pathname; |
17 | var gun | ||
18 | if (lru.has(pathname)){ | ||
19 | |||
20 | } else { | ||
21 | var gun = Gun({peers:[], ws: { noServer: true}}); | ||
22 | lru.set(pathname,gun); | ||
23 | } | ||
24 | |||
11 | if (pathname === '/gun1') { | 25 | if (pathname === '/gun1') { |
12 | wss_event.handleUpgrade(request, socket, head, function (ws) { | 26 | gun1.handleUpgrade(request, socket, head, function (ws) { |
13 | wss_event.emit('connection', ws); | 27 | gun1.emit('connection', ws); |
14 | }); | 28 | }); |
15 | } else if (pathname === '/gun2') { | 29 | } else if (pathname === '/gun2') { |
16 | wss_event.handleUpgrade(request, socket, head, function (ws) { | 30 | gun2.handleUpgrade(request, socket, head, function (ws) { |
17 | wss_event.emit('connection', ws); | 31 | gun2.emit('connection', ws); |
18 | }); | 32 | }); |
19 | } else { | 33 | } else { |
20 | socket.destroy(); | 34 | socket.destroy(); | ... | ... |
1 | dependencies: | 1 | dependencies: |
2 | express: 4.17.1 | 2 | express: 4.17.1 |
3 | gun: 0.2020.401 | 3 | gun: 0.2020.401 |
4 | quick-lru: 5.1.0 | ||
4 | packages: | 5 | packages: |
5 | /@peculiar/asn1-schema/1.1.2: | 6 | /@peculiar/asn1-schema/1.1.2: |
6 | dependencies: | 7 | dependencies: |
... | @@ -533,6 +534,12 @@ packages: | ... | @@ -533,6 +534,12 @@ packages: |
533 | node: '>=0.6' | 534 | node: '>=0.6' |
534 | resolution: | 535 | resolution: |
535 | integrity: sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ== | 536 | integrity: sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ== |
537 | /quick-lru/5.1.0: | ||
538 | dev: false | ||
539 | engines: | ||
540 | node: '>=10' | ||
541 | resolution: | ||
542 | integrity: sha512-WjAKQ9ORzvqjLijJXiXWqc3Gcs1ivoxCj6KJmEjoWBE6OtHwuaDLSAUqGHALUiid7A1KqGqsSHZs8prxF5xxAQ== | ||
536 | /ramda/0.26.1: | 543 | /ramda/0.26.1: |
537 | dev: false | 544 | dev: false |
538 | optional: true | 545 | optional: true |
... | @@ -709,3 +716,4 @@ shrinkwrapVersion: 3 | ... | @@ -709,3 +716,4 @@ shrinkwrapVersion: 3 |
709 | specifiers: | 716 | specifiers: |
710 | express: ^4.17.1 | 717 | express: ^4.17.1 |
711 | gun: ^0.2020.401 | 718 | gun: ^0.2020.401 |
719 | quick-lru: ^5.1.0 | ... | ... |
-
Please register or sign in to post a comment