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

Route Level Apply Point #23

Closed
mark-bradshaw opened this issue Jul 11, 2015 · 4 comments
Closed

Route Level Apply Point #23

mark-bradshaw opened this issue Jul 11, 2015 · 4 comments

Comments

@mark-bradshaw
Copy link
Owner

What if we supported a route-level trumps-all configuration, where the route reports a list of policies per apply point. But maybe it's too confusing to allow the plugin, the policy, and the route to report an apply point. Found myself brainstorming :P

server.route({
    method: 'GET',
    path: '/admin',
    handler: function(request, reply) {},
    config: {
        plugins: {
            policies: {
                onPreHandler: [
                    ['isLoggedIn', 'isAnAdmin'], // Do these two in parallel
                    'onlyInUS'
                ]
            }
        }
    }
});
@mark-bradshaw
Copy link
Owner Author

I moved this one over into its own issue so we can deal with them separately. My assumption was that policies would be apply point specific due to their own implementation needs, but I shouldn't make assumptions. I can see that there might be cases where you might want to apply a policy at different points for different routes. In a way this is getting closer and closer to Hapi pre-reqs, and perhaps the new Hapi 9 movement.

I guess the more I think about it the more I like the idea. It's an alternate way of making things work that should provide a new bit of flexibility. I like it.

@devinivy
Copy link
Collaborator

devinivy commented Oct 5, 2015

Let's see what happens in hapi 9.4 and 10.4 before moving on this: hapijs/hapi#2566 . @mark-bradshaw think we should make a milestone for #22 and this issue? Makes sense to do this major version bump of mrhorse soon after the 10.4 feature release.

@mark-bradshaw
Copy link
Owner Author

Yeah, I think you're right. Given the discussions about route extensions and such, there's a lot of flux. Best to let it settle before jumping.

@devinivy
Copy link
Collaborator

@mark-bradshaw I wrote a plugin that allows one to safely transform route configurations at the time of route registration. This would allow us to recreate the functionality of mrhorse, but with "native" route-level request extensions. As-is, routeDefn.config.plugins.policies would be transformed from a collection of policies into request extension objects { type, method, options } then placed on routeDefn.config.ext. Here's a sort of prototype for barebones post-requisites, to give you an idea of how it could work: https://github.com/devinivy/loveboat-postreqs

This would be a very different direction for mrhorse. It would be a transform for loveboat rather than a hapi plugin. I only suggest it because it doesn't seem like hapi has any plans for a programmatic interface to adding route-level server extensions, although Eran did mention the idea a while ago. If you have any other ideas to get native route-level request extensions, I think it's definitely an interesting topic!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants