Skip to content

ogourment/settings

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Never forget --settings.json again!

Reliably initialize Meteor.settings Build Status

This package provides a MeteorSettings object with only one function: setDefaults. This function works on the client or server.

Installation

meteor add ogourment:settings

Provide sensible defaults

Call MeteorSettings.setDefaults(defaultSettings) to populate the Meteor.settings object with sensible defaults for your app. If you do this in all the source files where you access Meteor.settings, this will ensure your app does not crash when accessing a setting, or avoid duplicating the code that checks if the settings are not empty. You should set the defaults for the settings used in the .js file for better modularity. You may call setDefaults as many times as you like.

Example:

MeteorSettings.setDefaults({
  public: {
    book: { title: "My Story" }
  }
});
...
// code that uses `Meteor.settings.public.book.title`

Alert the user when no settings were provided

Sometimes, there are no sensible defaults. In that case, you want to alert the developer when he forgot to provide a settings.json file. This usually only makes sense on the server. In this case, pass MeteorSettings.REQUIRED as the second argument. An Error will be thrown and the server will crash (nicely). If you want the settings file to only be required in production, pass MeteorSettings.REQUIRED_IN_PROD.

Example:

MeteorSettings.setDefaults({
  public: {
    book: { title: "My Story" }
  }
}, MeteorSettings.REQUIRED_IN_PROD);

...will result in the default "My Story" book title to be used. This will be true in development and the clients. On the server and when deployed on meteor.com or in any other production environment, it will fail with: settings-required Error

Troubleshooting

  1. Make sure to read the official doc on Meteor.settings. Note: only public settings are passed to the client.
  2. A detailed example is provided.
  3. Look at the tests to see what is supported.

Feedback welcome! Please send me an email ogourment @ smarterportal.com, or create an issue.

Thanks to Sam for the idea.

About

Reliably initialize Meteor.settings

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages