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
40ac9c72
authored
2020-04-16 22:27:29 +0200
by
Lorenzo Mangani
Committed by
GitHub
2020-04-16 22:27:29 +0200
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Update server.js
1 parent
4828c671
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
7 deletions
server.js
server.js
View file @
40ac9c7
/* Gun Multi-WS Monster */
/* Spawn multiple Gun WebSockets from the same HTTP/HTTPS server
* Each Gun is scoped to its ws.path and intended for ephemeral usage
* MIT Licensed (C) QXIP 2020
*/
const
url
=
require
(
'url'
);
const
Gun
=
require
(
'gun/gun'
);
require
(
'./gun-ws.js'
);
...
...
@@ -7,7 +13,7 @@ var server = http.createServer();
// LRU with last used sockets
const
QuickLRU
=
require
(
'quick-lru'
);
const
lru
=
new
QuickLRU
({
maxSize
:
1
});
const
lru
=
new
QuickLRU
({
maxSize
:
1
0
});
//var wss_event = new WebSocket.Server({ noServer: true});
...
...
@@ -29,7 +35,8 @@ server.on('upgrade', async function (request, socket, head) {
gun
.
gun
=
new
Gun
({
peers
:[],
// should we use self as peer?
localStorage
:
false
,
file
:
Math
.
random
().
toString
(
36
).
substring
(
7
),
file
:
"tmp/"
+
Math
.
random
().
toString
(
36
).
substring
(
7
),
// neesa cleanup or better mechanism to isolate
multicast
:
false
,
ws
:
{
noServer
:
true
,
path
:
pathname
,
web
:
gun
.
server
},
web
:
gun
.
server
});
...
...
@@ -39,10 +46,8 @@ server.on('upgrade', async function (request, socket, head) {
}
if
(
gun
.
server
){
// Handle Request
console
.
log
(
'handle connection...'
);
//ws.emit('connection', socket);
gun
.
server
.
handleUpgrade
(
request
,
socket
,
head
,
function
(
ws
)
{
console
.
log
(
'connecting to gun
..
'
,
gun
.
gun
.
opt
().
_
.
opt
.
ws
.
path
)
console
.
log
(
'connecting to gun
instance
'
,
gun
.
gun
.
opt
().
_
.
opt
.
ws
.
path
)
gun
.
server
.
emit
(
'connection'
,
ws
,
request
);
});
...
...
@@ -51,5 +56,5 @@ server.on('upgrade', async function (request, socket, head) {
}
});
server
.
listen
(
3000
);
\ No newline at end of file
//
server
.
listen
(
3000
);
...
...
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