Disable user hook in sails

♀尐吖头ヾ 提交于 2020-01-02 07:06:00

问题


I'm using sails on a project hosted on Heroku. I have a web process running a sails web server and a worker process using the same Models as the ones used by the web server.

In order to make it possible I have different way to start each process with the same code :

  1. the app.js standard way
  2. a worker.js file that starts the same sails app with only the orm and services hook activated.

However I have added some user hooks in a api/hooks folder that I don't want the worker to start. Is there an easy way to disable those hooks? I tried to lift sails with a { "userhookname" : false } passed in config but it does not seem to work.

Thank you


回答1:


Sails.js doesn't currently support disabling individual user hooks in the same way as the core hooks, although it certainly makes sense to implement that feature. In the meantime, the simplest thing to do is to just implement a toggle within the hook itself. In the defaults, provide an active key that defaults to true, and then in initialize, check that active is true before continuing. See sails-hook-autoreload for an example.



来源:https://stackoverflow.com/questions/30580472/disable-user-hook-in-sails

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!