hapijs / glue

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

dependency issue #34

Closed danielb2 closed 8 years ago

danielb2 commented 8 years ago

I'm loading a local plugin with a dependency on h2o2, but seeing Unknown handler: proxy error

Ref: https://gist.github.com/danielb2/78309eaf53d533407642

If I change the order of the manifest file (loading h2o2 first), the test will pass. I could use the array syntax for registering the plugins in the correct order, but the Glue documentation leads me to believe using server.dependency will take care of it for me.

Am I missing something? I got this working just fine with 0.10.4 at one point

devinivy commented 8 years ago

Actually server.dependency does not reorder your plugins in any way. It should, however, throw an error if the dependencies are not met when the server is initialized.

danielb2 commented 8 years ago

That's what I would think, however, this part of the documentation can be misread to read otherwise:

When using an array as the value, then the plugin registration order follows the array order. If you are developing a plugin, you should ensure your plugin dependencies are properly managed to guarantee that all dependencies are loaded before your plugin registration completes. See server.dependency(dependencies, [after]) for more information.

It could be read to suggest that server.dependency may help with the order when not using array order.

zoe-1 commented 8 years ago

@danielb2 sever.dependency does not enforce dependencies to be loaded first. You want to use: server.dependency(dependencies, [after])

`internals = {};

exports.register = function (server, options, next) {

    // the registration logic in internals.after will be executed on server start, 
    // and only after dependencies are fully registered. 
    server.dependency(['hapi-auth-cookie', 'hapi-mongo-models'], internals.after);

    next();
};

// all the registration logic depends on other plugins (uses schemes and plugins-specific space), 
// so we extract it so that we can set it up to be fired only after dependency resolution
internals.after = function(server, next){

    var Session = server.plugins['hapi-mongo-models'].Session;
    var User = server.plugins['hapi-mongo-models'].User;

    // Plugin code here.

    next();
};

See My Explanation in the ReadMe of my glue fork Eventually, I need to put that explanation in a hapijs.com tutorial

zoe-1 commented 8 years ago

Also see docs: http://hapijs.com/api#serverdependencydependencies-after

devinivy commented 8 years ago

I agree with @danielb2 that the docs are misrepresenting server.dependency.

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.