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

Pass plugin's server rather than root server to route config function #3297

Closed
devinivy opened this issue Aug 21, 2016 · 3 comments
Closed
Assignees
Labels
feature New functionality or improvement
Milestone

Comments

@devinivy
Copy link
Member

devinivy commented Aug 21, 2016

In #3277 (v14.1) the ability to specify a route's config as a function was introduced. That function currently receives the root server as an argument. I would suggest passing the relevant plugin's server instead, and additionally the relevant plugin's options as a second argument. I find this to be more multi-purpose (since the root is trivially found accessible the plugin's server) and possibly more consistent with the original use-case that the feature was intended to cater to.

To illustrate,

server.route({
  path: '/',
  method: 'get',
  config: (srv, opts) => {

    Hoek.assert(srv === server);
    Hoek.assert(opts === server.realm.pluginOptions);

    const { serverLevelConfig } = srv.app;
    const { pluginLevelOptions } = opts;

    return { handler: (request, reply) => reply(serverLevelConfig + pluginLevelOptions) };
  }
});
@hueniverse
Copy link
Contributor

Well, it works great for the user case I had for it... :-)

@devinivy
Copy link
Member Author

I suppose every application is its own special snowflake. :o)

@hueniverse hueniverse added this to the 17.0.0 milestone Oct 18, 2017
@hueniverse hueniverse self-assigned this Oct 18, 2017
@hueniverse
Copy link
Contributor

Use plugin.realm.parent.

@Marsup Marsup added feature New functionality or improvement and removed request labels Sep 20, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Mar 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature New functionality or improvement
Projects
None yet
Development

No branches or pull requests

3 participants