View our GitHub

Please visit sails-docs on GitHub to view documentation on your mobile device.

Edit Page


The configure feature provides a way to configure a hook after the defaults objects have been applied to all hooks. By the time a custom hook’s configure() function runs, all user-level configuration and core hook settings will have been merged into sails.config. However, you should not depend on other custom hooks’ configuration at this point, as the load order of custom hooks is not guaranteed.

configure should be implemented as a function with no arguments, and should not return any value. For example, the following configure function could be used for a hook that communicates with a remote API, to change the API endpoint based on whether the user set the hook’s ssl property to true. Note that the hook’s configuration key is available in configure as this.configKey:

configure: function() {

   // If SSL is on, use the HTTPS endpoint
   if (sails.config[this.configKey].ssl == true) {
      sails.config[this.configKey].url = "https://" + sails.config[this.configKey].domain;
   // Otherwise use HTTP
   else {
      sails.config[this.configKey].url = "http://" + sails.config[this.configKey].domain;

The main benefit of configure is that all hook configure functions are guaranteed to run before any initialize functions run; therefore a hook’s initialize function can examine the configuration settings of other hooks.

Is something missing?

If you notice something we've missed or could be improved on, please follow this link and submit a pull request to the sails-docs repo. Once we merge it, the changes will be reflected on the website the next time it is deployed.