禁用风帆中的用户挂钩 [英] Disable user hook in sails

查看:29
本文介绍了禁用风帆中的用户挂钩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Heroku 上托管的项目中使用了风帆.我有一个 web 进程运行一个sails web 服务器和一个工作进程,它使用与 web 服务器使用的模型相同的模型.

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. app.js 标准方式
  2. 一个 worker.js 文件,它启动同一个sails 应用程序,只激活了 orm 和 services 挂钩.

但是我在 api/hooks 文件夹中添加了一些我不希望工作人员启动的用户挂钩.有没有一种简单的方法来禁用这些钩子?我试图用在配置中传递的 { "userhookname" : false } 举起帆,但它似乎不起作用.

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.

谢谢

推荐答案

Sails.js 当前不支持以与核心钩子相同的方式禁用单个用户钩子,尽管实现该功能当然是有意义的.同时,最简单的做法是在钩子本身内实现一个切换.在 defaults 中,提供一个默认为 trueactive 键,然后在 initialize 中,检查 active 在继续之前是 true.请参阅 sails-hook-autoreload 了解一个例子.

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.

这篇关于禁用风帆中的用户挂钩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆