From c0e8de95c7f48386a033e01785c8e775f95e7547 Mon Sep 17 00:00:00 2001 From: d3x0r Date: Fri, 24 Mar 2017 10:56:56 -0700 Subject: [PATCH 1/2] Update for internals change gun.wsp doesn't exist. move .on hook up further add this.to.next. (still fails to serve chat example; others work) --- examples/http-external-ws.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/examples/http-external-ws.js b/examples/http-external-ws.js index 91b7d313..4a6f3d12 100644 --- a/examples/http-external-ws.js +++ b/examples/http-external-ws.js @@ -1,20 +1,24 @@ var port = process.env.OPENSHIFT_NODEJS_PORT || process.env.VCAP_APP_PORT || process.env.PORT || process.argv[2] || 8080; var Gun = require('../'); + +// have to do this before instancing gun(?) +Gun.on('out', function(msg){ + this.to.next( msg ); + msg = JSON.stringify(msg); + gunPeers.forEach( function(peer){ peer.send( msg ) }) +}) + var gun = Gun({ - file: 'data.json', - s3: { - key: '', // AWS Access Key - secret: '', // AWS Secret Token - bucket: '' // The bucket you want to save into - } + file: 'data.json' }); var server = require('http').createServer(function(req, res){ - if(gun.wsp.server(req, res)){ - return; // filters gun requests! - } - require('fs').createReadStream(require('path').join(__dirname, req.url)).on('error',function(){ // static files! + var insert = ""; + if( req.url.endsWith( "gun.js" ) ) + insert = "../"; + + require('fs').createReadStream(require('path').join(__dirname, insert, req.url)).on('error',function(){ // static files! res.writeHead(200, {'Content-Type': 'text/html'}); res.end(require('fs').readFileSync(require('path').join(__dirname, 'index.html'))); // or default to index }).pipe(res); // stream @@ -35,10 +39,6 @@ wss.on('connection',acceptConnection ) var gunPeers = []; // used as a list of connected clients. -Gun.on('out', function(msg){ - msg = JSON.stringify(msg); - gunPeers.forEach( function(peer){ peer.send( msg ) }) -}) function acceptConnection( connection ) { // connection.upgradeReq.headers['sec-websocket-protocol'] === (if present) protocol requested by client // connection.upgradeReq.url === url request From 62eb748f939ac5bed2dfd3970bda7eb290f4cd8a Mon Sep 17 00:00:00 2001 From: d3x0r Date: Fri, 24 Mar 2017 11:00:09 -0700 Subject: [PATCH 2/2] Formatting fix. --- examples/http-external-ws.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/http-external-ws.js b/examples/http-external-ws.js index 4a6f3d12..0099ca79 100644 --- a/examples/http-external-ws.js +++ b/examples/http-external-ws.js @@ -14,9 +14,9 @@ var gun = Gun({ }); var server = require('http').createServer(function(req, res){ - var insert = ""; + var insert = ""; if( req.url.endsWith( "gun.js" ) ) - insert = "../"; + insert = "../"; require('fs').createReadStream(require('path').join(__dirname, insert, req.url)).on('error',function(){ // static files! res.writeHead(200, {'Content-Type': 'text/html'});