Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Jabis Sev贸n
/
gun-multiserver
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
1dd53103
authored
2020-04-15 18:14:15 +0000
by
Glitch (hello-express)
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Checkpoint
./server.js:13690106/434 ./package.json:13690106/1337
1 parent
8a023531
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
5 deletions
package.json
server.js
shrinkwrap.yaml
package.json
View file @
1dd5310
...
...
@@ -11,7 +11,8 @@
},
"dependencies"
:
{
"express"
:
"^4.17.1"
,
"gun"
:
"^0.2020.401"
"gun"
:
"^0.2020.401"
,
"quick-lru"
:
"^5.1.0"
},
"engines"
:
{
"node"
:
"12.x"
...
...
server.js
View file @
1dd5310
...
...
@@ -4,17 +4,31 @@ const http = require('http');
const
WebSocket
=
require
(
'ws'
);
var
server
=
http
.
createServer
().
listen
(
3000
);
var
gun1
=
Gun
({
peers
:[],
ws
:
{
noServer
:
true
}});
var
gun2
=
Gun
({
peers
:[],
ws
:
{
noServer
:
true
}});
const
QuickLRU
=
require
(
'quick-lru'
);
const
lru
=
new
QuickLRU
({
maxSize
:
100
});
var
wss_event
=
new
WebSocket
.
Server
({
noServer
:
true
});
server
.
on
(
'upgrade'
,
function
(
request
,
socket
,
head
)
{
var
pathname
=
url
.
parse
(
request
.
url
).
pathname
;
var
gun
if
(
lru
.
has
(
pathname
)){
}
else
{
var
gun
=
Gun
({
peers
:[],
ws
:
{
noServer
:
true
}});
lru
.
set
(
pathname
,
gun
);
}
if
(
pathname
===
'/gun1'
)
{
wss_event
.
handleUpgrade
(
request
,
socket
,
head
,
function
(
ws
)
{
wss_event
.
emit
(
'connection'
,
ws
);
gun1
.
handleUpgrade
(
request
,
socket
,
head
,
function
(
ws
)
{
gun1
.
emit
(
'connection'
,
ws
);
});
}
else
if
(
pathname
===
'/gun2'
)
{
wss_event
.
handleUpgrade
(
request
,
socket
,
head
,
function
(
ws
)
{
wss_event
.
emit
(
'connection'
,
ws
);
gun2
.
handleUpgrade
(
request
,
socket
,
head
,
function
(
ws
)
{
gun2
.
emit
(
'connection'
,
ws
);
});
}
else
{
socket
.
destroy
();
...
...
shrinkwrap.yaml
View file @
1dd5310
dependencies
:
express
:
4.17.1
gun
:
0.2020.401
quick-lru
:
5.1.0
packages
:
/@peculiar/asn1-schema/1.1.2
:
dependencies
:
...
...
@@ -533,6 +534,12 @@ packages:
node
:
'
>=0.6'
resolution
:
integrity
:
sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ==
/quick-lru/5.1.0
:
dev
:
false
engines
:
node
:
'
>=10'
resolution
:
integrity
:
sha512-WjAKQ9ORzvqjLijJXiXWqc3Gcs1ivoxCj6KJmEjoWBE6OtHwuaDLSAUqGHALUiid7A1KqGqsSHZs8prxF5xxAQ==
/ramda/0.26.1
:
dev
:
false
optional
:
true
...
...
@@ -709,3 +716,4 @@ shrinkwrapVersion: 3
specifiers
:
express
:
^4.17.1
gun
:
^0.2020.401
quick-lru
:
^5.1.0
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment