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

dependency issue #34

Closed
danielb2 opened this issue Sep 29, 2015 · 6 comments
Closed

dependency issue #34

danielb2 opened this issue Sep 29, 2015 · 6 comments

Comments

@danielb2
Copy link

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
Copy link
Member

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
Copy link
Author

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
Copy link

zoe-1 commented Sep 29, 2015

@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
Copy link

zoe-1 commented Sep 29, 2015

@devinivy
Copy link
Member

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

@lock
Copy link

lock bot commented Jan 9, 2020

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.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants