Skip to content

Instantly share code, notes, and snippets.

@mikermcneil
Last active January 3, 2016 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikermcneil/8513795 to your computer and use it in GitHub Desktop.
Save mikermcneil/8513795 to your computer and use it in GitHub Desktop.
/* Kasper (18c98c26@gateway/web/freenode/ip.24.201.140.38) has joined #sailsjs
<Kasper> Hi there!
<Kasper> Anyone got time for a question?
<robdubya> nothing but time Kasper
<Kasper> Wonderful! It's related to Services: How would I access the Sails config when writing a service?
* sailsTroll (~nodebot@ec2-54-209-111-37.compute-1.amazonaws.com) has joined #sailsjs
<robdubya> ha Kasper, how prescient of you
*/
// api/services/FooService.js
module.exports = {
/**
* Some function that does stuff.
*
* @param {[type]} options [description]
* @param {Function} cb [description]
*/
lookupDumbledore: function(options, cb) {
// `sails` object is available here:
var conf = sails.config;
cb(null, conf.whatever);
}
};
// `sails` is not available here (it doesn't exist yet)
@mikermcneil
Copy link
Author

this answers the question:

How would I access the Sails config when writing a service?

@mikermcneil
Copy link
Author

Also see Create config variables in sails.js? for more details on other usage patterns.

@davesag
Copy link

davesag commented May 4, 2014

In my routes.js I am trying to set the page title within a route as per

'/index': {
  view: 'home/index',
  locals: {
    title: sails.config.myApp + ' | The Home Page'
  }
},

but it says ReferenceError: sails is not defined

How do I access configs within route definitions?

@marsanla
Copy link

marsanla commented Sep 9, 2014

+1

@seth2810
Copy link

seth2810 commented Oct 1, 2014

+1

@lrdiv
Copy link

lrdiv commented Oct 9, 2014

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment