Create sails.js hooks with models
I want to create a sails.js hook that has its own model. How can I insert this model into the current application?
I found this: https://github.com/leeroybrun/sails-hook-hookloader but I don't understand how it works.
Thank,
+3
source to share
1 answer
I found an easy way to do it!
I just created symbolic links of all hook model files to the main "api / models" folder of the application!
My initialization function looks like this:
var path = require('path');
var fs = require('fs');
module.exports = function ToInitialize(sails) {
return function initialize(cb) {
// the path of the Hook model
var modelFile = path.join(__dirname, '../models/Model.js');
// the destination path
var modelFileDest = path.join(sails.config.appPath, 'api/models/Model.js');
if (!fs.existsSync(modelFileDest)) {
// create a symlink to the api/models folder
fs.symlink(modelFile, modelFileDest, 'file', cb);
} else {
return cb();
}
};
};
+2
source to share