Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Something like this should fix #422 #423

Merged
merged 1 commit into from
Sep 20, 2017
Merged

Something like this should fix #422 #423

merged 1 commit into from
Sep 20, 2017

Conversation

d3x0r
Copy link
Contributor

@d3x0r d3x0r commented Sep 19, 2017

No description provided.

@sergibondarenko
Copy link

I tried your patch in my scripts #422, it didn't work

Added support to take opt as a string
Promote simple opt as a string to opt.peers[opt] .
@sergibondarenko
Copy link

sergibondarenko commented Sep 19, 2017

I still don't receive any data. Steps to reproduce are below.

  1. Download your repo and checked into your patch, folder ~/dev/learn/gun/gun.
trex@beast-cave:~/dev/learn/gun/gun$ git remote -v
origin  git@github.com:d3x0r/gun.git (fetch)
origin  git@github.com:d3x0r/gun.git (push)
trex@beast-cave:~/dev/learn/gun/gun$ git branch
  master
* patch-17
trex@beast-cave:~/dev/learn/gun/gun$ git pull
Already up-to-date.
  1. Have the graph tutorial data available, full data is here, folder ~/dev/learn/gun/server.
trex@beast-cave:~/dev/learn/gun/server$ head -c 200 data.json
{"person/alice":{"_":{"#":"person/alice",">":{"name":1505750977100,"age":1505750977100,"spouse":1505750977133.001,"employer":1505750977141.002}},"name":"alice","age":22,"spouse":{"#":"person/bob"},"em...
  1. Run server, folder ~/dev/learn/gun/server
    Run node hapi.js
trex@beast-cave:~/dev/learn/gun/server$ cat hapi.js
const Hapi  = require('hapi')
const Inert = require('inert')
const Gun   = require('../gun/')

const server = new Hapi.Server
server.connection({ port: 8080 })
server.connections.forEach(c => Gun({ web: c.listener, file: 'data.json' }))

server.register(Inert, () => {});

server.route({
  method: 'GET',
  path: '/gun.js',
  handler: (request, reply) => reply.file('./gun.js', { confine: false })
})

server.route({
  method: 'GET',
  path: '/{param*}',
  handler: {
    directory: {
      path: __dirname,
      redirectToSlash: true,
      index: true
    }
  }
})

server.start()
  1. Query data, folder ~/dev/learn/gun/graph
    Run: node graph.js
trex@beast-cave:~/dev/learn/gun/graphs$ cat graphs.js
const Gun = require('gun');
const gun = Gun({ peers:['http://localhost:8080/gun'] });
gun.get('person/alice').get('spouse').get('employer').get('employees').map().get('name').val(function(data, key){
  console.log("The employee's", key, data);
});

No results in the console output.

@sergibondarenko
Copy link

I tested this patch with my example and it worked.

@amark
Copy link
Owner

amark commented Sep 20, 2017

@d3x0r you are a life saver! I'm still confused why this works??? (if(!x) return versus if(x) do?) Pulling.

@amark amark merged commit 5c0a80a into amark:master Sep 20, 2017
@d3x0r
Copy link
Contributor Author

d3x0r commented Sep 20, 2017

@amark :) because the if( x) do only does the top open/attach server part...( or rather if not set, only doesn't do the top part) the remaining ctx.on()s were being skipped with the return at the top... so this allows the on( out ) to be regsitered and trigger opening the peers as required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants