I have a custom sails.js hook which implements a Websocket server (we can't use the built-in socket.js
hook because we needed to match an old API).
I also have a custom sails run
script that does background processing.
Right now, when the sails run -name-of-my-script
command is run, it also runs my hook which makes extra listeners for all of the events used by this hook.
I would like to make it that the hook only starts on a main application startup (sails lift
or the equivalent node app.js
), not on sails run ...
.
I have looked through the code and the documentation, but I can't seem to see any official way to do this.
I can think of two options:
Is there any way to do either of those things?
Right now, there is no built-in way to do this because Sails scripts have no way to modify configuration - they use the default sails
instance with its default settings.
Here is the hack that I used to make it work:
Add a check for a configuration option in the hook's initialize method:
if (app.config.notifier.active === false) {
sails.log.verbose('Notifier disabled');
return cb();
}
// Continue with notifier hook setup here
Add setting an environment variable to the top of the script (before the module.exports
:
process.env.sails_notifier__active = false;
(Note: Step 1 is based on this answer but the package linked there no longer uses this technique. That question and answer are also extremely old -- at least as Sails.js answers go -- from before sails run
existed.)
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加