hapijs / glue

Server composer for hapi.js
Other
245 stars 62 forks source link

Where can i place Callback function with Glue.compose.bind #100

Closed sibinx7 closed 7 years ago

sibinx7 commented 7 years ago
const Glue = require('glue')
const Manifest = require('./manifest')

const composeOptions = {
  relativeTo: __dirname
}
Glue.compose.bind(Glue, Manifest.get('/'), composeOptions)
#manifest file 
    {
      plugin:{
        register: 'bell'
      }
    },

Where i can pass callback to register bell auth stractegy

csrl commented 7 years ago

The glue configuration schema for a plugin registration is:

{
  plugin: {
    register: <plugin_to_register>,
    options: <plugin_options>
  },
  options: <registration_options>
}

Which translates into a hapi server call of:

server.register({register: <plugin_to_register>, options: <plugin_options>}, <registration_options>)

So if you follow bell's documentation, the mapping should become apparent.

sibinx7 commented 7 years ago

Thanks @csrl

Can you give me an example with this

server.register(require('bell'), function (err) {
    server.auth.strategy('twitter', 'bell', {
        provider: 'twitter',
        password: 'cookie_encryption_password_secure',
        clientId: 'my_twitter_client_id',
        clientSecret: 'my_twitter_client_secret',
        isSecure: false     // Terrible idea but required if not using HTTPS especially if developing locally
    });
})

Can u give me one example with this.

Project use Glue.compose.bind() method than Glue.compose, second one, we can use callback

Glue.compose(manifest, options, (err,server) => {})
  1. How can i do with Glue.compose.bind
  2. How can i add this on
    {
    plugin: {
    register: <plugin_to_register>,
    options: <plugin_options>
    },
    options: <registration_options>
    }

Thanks in advance ...

csrl commented 7 years ago

call server.auth.strategy in the compose callback that provides the 'server' object.

sibinx7 commented 7 years ago
Glue.compose.bind(Glue, Manifest.get('/'), composeOptions, composeCallback)

when i add callback ,i got argument error

throw new Error(msgs.join(' ') || 'Unknown error'); ^ Error: Invalid number of arguments

csrl commented 7 years ago

What is the purpose of using bind? You'll get "Invalid number of arguments" error if you pass more than 3 arguments to compose, but from what you pasted you are not doing that. The only thing I can think is you are doing something else weird since you are using bind in the first place.

In any case, I can't reproduce the error:

$ node
> var Glue = require("./")
undefined
> var compose = Glue.compose.bind(Glue,{},{}, (err,server) => {console.log(err,!!server)})
[Function: bound ]
> compose()
undefined
> null true
>

You'll have to provide a minimal example that produces the error that I can test.

(edit: for completeness)

csrl commented 7 years ago

Feel free to reopen if you still have any question.

lock[bot] commented 4 years ago

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.