senecajs / seneca-web

Http route mapping for Seneca microservices.
MIT License
76 stars 44 forks source link

Endpoints are not registered to Hapi when using Seneca 2.0.0 #59

Closed mirceaalexandru closed 8 years ago

mirceaalexandru commented 8 years ago
var Hapi = require ( 'hapi' )

var server = new Hapi.Server({ debug: { request: ['error'] } })
server.connection({port: 3000})

server.register(
  {
    register: require('chairo'),
    options: {
      seneca: require('seneca')()
    }
  }, function (err) {
    var seneca = server.seneca

    seneca.add('role:api,cmd:ping', function (args, done) {
      done(null, {pong: true})
    })

    seneca.act('role:web', {
      use: {
        prefix: '/api',
        pin: {role: 'api', cmd: '*'},
        map: {
          ping: true,
        }
      }
    })

    server.start(function (err) {
    })
  })
curl http://localhost:3000/api/ping
{"statusCode":404,"error":"Not Found"}

If Chairo options do not contain seneca, so seneca 1.4.0 will be used then I have:

curl http://localhost:3000/api/ping
{"pong":true}

@geek I am looking on this but maybe I will need some help.

mirceaalexandru commented 8 years ago

@geek

https://github.com/senecajs/seneca/blob/master/seneca.js#L949

seems that is never called

mirceaalexandru commented 8 years ago
    seneca.use(require('seneca-cron'))

    seneca.ready(function(){
      console.log('READY CALLED')
      seneca.use(require('seneca-user'))
    })

when using seneca 2.0 the above ready function is never called. With 1.4.0. this is called correctly

rjrodger commented 8 years ago

@mirceaalexandru can you write a seneca unit test in the main seneca repo that reproduces this priblem - thanks

mirceaalexandru commented 8 years ago

yes, I will do it now

mirceaalexandru commented 8 years ago

@rjrodger seems to be working now - the ready() is called, even if it do not seems to be in the expected order - at least in my opinion. I am preparing a repo with an example for this