sgress454 / sails-hook-autoreload

Sails JS hook to autoreload controllers and models when changed.
231 stars 44 forks source link

[1.0.0] Can't reload policies as in 0.12 #81

Open Fr33maan opened 7 years ago

Fr33maan commented 7 years ago

I don't understand how to reload policies. sails.hooks.policies.initialize(cb) will duplicate policies instead of replacing them. router.flush() does not seems to help.

I posted a message on gitter:

Hi sails team, I'm experiencing issues in sails-hook-autoreload and another hook with sails@1. I want to reload policies / edit policies w/ the hook. In sails 0.12 it was very easy but now I don't understand how to do that. If I simple do sails.hooks.policies.initialize(), policies get duplicated in sails@1. If I edit the sails.config.policies array nothing happens when I hit the route. I think that policies are directly binded in the router but even a router.flush does not work. How should I do to fully reload policies without relifting the server ? Thanks

Fr33maan commented 7 years ago

@sgress454 Maybe you have a spontaneous answer ? :D

sgress454 commented 7 years ago

@l1br3 I'm afraid not. Policies in Sails 1.0 are implement as action middleware, and there's currently no mechanism for reloading the set of loaded action middleware. The only thing you could do is set sails._actionMiddleware = []; to clear out the current set, which might work, but is using the private API so caveat emptor. Plus if any other hooks had added middleware (unlikely, but possible), they wouldn't know to reload.

Fr33maan commented 7 years ago

@sgress454 That's a radical change. But maybe the solution to add policies with hooks ? I need it for my sails-role-permissions hook

Fr33maan commented 7 years ago

@sgress454 Maybe I could list user's hooks to reload them once action middleware has been flushed ?