Security News
The Dark Side of Open Source
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
sails-util-mvcsloader
Advanced tools
Readme
Load models, controllers, services, policies and config from specified directories and inject them into the main Sails app.
This is partically usefull to extend your Sails app from hooks.
You can have create new models/controllers/etc in your hook, and have them loaded into the main Sails app.
You can even extend models/controllers/etc already existing in your main Sails app with specific methods/properties from your hooks.
You have to install it in the project from where you will load the models/controllers/etc.
If you want to load MVCS from a hook in your main Sails' app (living in the hooks/ folder), install it in your Sails app's main folder.
If you want to load MVCS from an installable hook (separate NPM package), install it directly in your installable hook's main folder.
Run this command to install and add the package as a dependency in your package.json :
npm install --save sails-util-mvcsloader
You can find a complete hook example in the example folder.
Using this module is pretty easy.
In your hook's index.js file, require the module and pass your Sails app as first argument :
module.exports = function(sails) {
var loader = require('sails-util-mvcsloader')(sails);
...
return {
initialize: function (next) {
...
}
};
};
You can load config and policies with the configure
method.
This method is synchronous and MUST be called before the hook initialisation, outside the initialize method.
If you don't want/need to load config or policies, you don't have to call this method.
Use it like this (complete example below):
// Load policies under ./api/policies and config under ./config
loader.configure();
Or like this if you want to load from specific directories:
loader.configure({
policies: __dirname + '/api/policies',// Path to the policies to load
config: __dirname + '/config' // Path to the config to load
});
To load models, controllers and services, call the inject
method.
This method is asynchronous and must be called after the configure
method (presented above), if you need to load config and policies.
Use it like this (complete example below):
/*
Load models under ./api/models
Load controllers under ./api/controllers
Load services under ./api/services
*/
loader.inject(function (err) {
return next(err);
});
Or like this if you want to load from specific directories:
loader.adapt({
controllers: __dirname + '/controllers', // Path to the controllers to load
models: __dirname + '/models', // Path to the models to load
services: __dirname + '/services' // Path to the services to load
}, function (err) {
return next(err);
});
Here is a complete example. It's the index.js file of a Sails hook.
module.exports = function(sails) {
var loader = require('sails-util-mvcsloader')(sails);
// Load policies under ./api/policies and config under ./config
loader.configure();
/*
OR if you want to set a custom path :
loader.configure({
policies: __dirname + '/api/policies',// Path to your hook's policies
config: __dirname + '/config'// Path to your hook's config
});
*/
return {
initialize: function (next) {
/*
Load models under ./api/models
Load controllers under ./api/controllers
Load services under ./api/services
*/
loader.inject(function (err) {
return next(err);
});
/*
OR if you want to set a custom path :
loader.inject({
controllers: __dirname + '/controllers', // Path to your hook's controllers
models: __dirname + '/models', // Path to your hook's models
services: __dirname + '/services' // Path to your hook's services
}, function (err) {
return next(err);
});
*/
}
};
}
For now, we use 4 spaces instead of 2.
For the rest, please follow the Felix's Node.js Style Guide.
We use semantic versioning for the NPM package.
FAQs
Load models, controllers, services, policies and config from specified directories and inject them into the main Sails app.
The npm package sails-util-mvcsloader receives a total of 55 weekly downloads. As such, sails-util-mvcsloader popularity was classified as not popular.
We found that sails-util-mvcsloader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
Research
Security News
The Socket Research team found this npm package includes code for collecting sensitive developer information, including your operating system username, Git username, and Git email.
Security News
OpenJS is warning of social engineering takeovers targeting open source projects after receiving a credible attempt on the foundation.