Search code examples
sails.jscontrollerspolicies

Defining policies inside controllers in sails.js


Sails.js (0.9v) controllers has a *_config function* to override configs from config file.

is there any _policies function to define the policies inside the controllers itself?

Thanks


Solution

  • Policies can already be specified on per-controller basis in the /config/policies.js file, so there's no benefit in having the configuration exist inside the controller file as well. See the comments inside /config/policies for information on how to attach a policy to a specific controller or action. Also keep in mind that in Sails v0.10, the _config key is still valid inside controller files, but the configuration properties should be put at the top level, not under blueprints, e.g.:

    _config: {
       rest: false,
       actions: false,
       shortcuts: false
    }
    

    These will override the settings in your /config/blueprints.js file.