write-sails-hook

how to write one sails-hook

  • you module package.json must have key ‘sails’ , it’s a object, with contain key isHook, if want to replace default hook, you can add key hookName, eg: sails:{isHook:true,hookName:’orm’}
  • export a function and return object, the first param is sails

sails hook how to load?

load hook principle : https://github.com/balderdashy/sails/blob/v0.12.3/lib/hooks/moduleloader/index.js#L507

replace default hook : https://github.com/balderdashy/sails/blob/v0.12.3/lib/hooks/moduleloader/index.js#L513

example

package.json

1
2
3
4
5
6
7
{
"version":"0.0.1",
"sails": {
"isHook": true,
"hookName": "test"
}
}

index.js(export)

1
2
3
4
5
6
module.exports = function(sails){
console.log('010101010101010101')
return {

}
}
{% if theme.baidu_push %} {% endif %}