Last active
June 28, 2017 04:52
-
-
Save ndabAP/1dfa9a033af7979f7b18e019a3028786 to your computer and use it in GitHub Desktop.
Use nested services instead of helpers within Sails.js 1.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// config/bootstrap.js | |
module.exports.bootstrap = function (done) { | |
const path = require('path') | |
// Install the required package first | |
sails.services = require('include-all')({ | |
dirname: path.resolve('api/services'), | |
filter: /(.+Service)\.js$/, | |
excludeDirs: /^\.(git|svn)$/ | |
}) | |
return done() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// api/controllers/SomeController.js | |
module.exports = { | |
/** | |
* @param req | |
* @param res | |
*/ | |
create: (req, res) => { | |
let love = sails.services.SomeService.getLove() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// api/services/SomeService.js | |
module.exports = { | |
getLove: () => { | |
return 'Love' | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment