40ac9c72 by Lorenzo Mangani Committed by GitHub

Update server.js

1 parent 4828c671
Showing 1 changed file with 11 additions and 6 deletions
/* 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: 10});
//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);
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!