Skip to content

Commit

Permalink
If Meteor.settings.public exists, make it available on the client as …
Browse files Browse the repository at this point in the history
…well.

(Suggested by @jagill at Meteor Dev Shop 0!)
  • Loading branch information
glasser committed Feb 9, 2013
1 parent c208f68 commit 4f2d725
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 16 deletions.
18 changes: 10 additions & 8 deletions app/meteor/meteor.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ Fiber(function () {
.boolean('debug')
.describe('debug', 'deploy in debug mode (don\'t minify, etc)')
.boolean('tests')
.describe('settings', 'set optional data for Meteor.settings on the server')
.describe('settings', 'set optional data for Meteor.settings')
// .describe('tests', 'deploy the tests instead of the actual application')
.usage(
// XXX document --tests in the future, once we publicly
Expand All @@ -532,22 +532,24 @@ Fiber(function () {
"\n" +
"You can deploy to any available name under 'meteor.com'\n" +
"without any additional configuration, for example,\n" +
"'myapp.meteor.com'. If you deploy to a custom domain, such as\n" +
"'myapp.meteor.com'. If you deploy to a custom domain, such as\n" +
"'myapp.mydomain.com', then you'll also need to configure your domain's\n" +
"DNS records. See the Meteor docs for details.\n" +
"DNS records. See the Meteor docs for details.\n" +
"\n" +
"The --settings flag can be used to pass deploy-specific information to\n" +
"the application. It will be available at runtime in Meteor.settings, but only\n" +
"on the server. The argument is the name of a file containing the JSON data\n" +
"to use. The settings will persist across deployments until you again specify\n" +
"a settings file. To unset Meteor.settings, pass an empty settings file.\n" +
"on the server. If the object contains a key named 'public', then\n" +
"Meteor.settings.public will also be available on the client. The argument\n" +
"is the name of a file containing the JSON data to use. The settings will\n" +
"persist across deployments until you again specify a settings file. To\n" +
"unset Meteor.settings, pass an empty settings file.\n" +
"\n" +
"The --delete flag permanently removes a deployed application, including\n" +
"all of its stored data.\n" +
"\n" +
"The --password flag sets an administrative password for the domain. Once\n" +
"The --password flag sets an administrative password for the domain. Once\n" +
"set, any subsequent 'deploy', 'logs', or 'mongo' command will prompt for\n" +
"the password. You can change the password with a second 'deploy' command."
"the password. You can change the password with a second 'deploy' command."
);

var new_argv = opt.argv;
Expand Down
5 changes: 3 additions & 2 deletions docs/client/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ Template.api.absoluteUrl = {
Template.api.settings = {
id: "meteor_settings",
name: "Meteor.settings",
locus: "Server",
locus: "Server and client",
descr: ["`Meteor.settings` contains any deployment-specific options that were " +
"provided using the `--settings` option for `meteor run` or `meteor deploy`. " +
"If you provide the `--settings` option, `Meteor.settings` will be the " +
"JSON object in the file you specify. Otherwise, `Meteor.settings` will " +
"be an empty object."]
"be an empty object. If the object contains a key named `public`, then " +
"`Meteor.settings.public` will also be available on the client."]
};

Template.api.publish = {
Expand Down
6 changes: 6 additions & 0 deletions packages/meteor/client_environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@ Meteor = {
isClient: true,
isServer: false
};

if (typeof __meteor_runtime_config__ !== 'undefined' &&
__meteor_runtime_config__ &&
__meteor_runtime_config__.PUBLIC_SETTINGS) {
Meteor.settings = { public: __meteor_runtime_config__.PUBLIC_SETTINGS };
}
16 changes: 10 additions & 6 deletions packages/meteor/server_environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ Meteor = {
isServer: true
};

try {
Meteor.settings = {};
if (process.env.METEOR_SETTINGS)
Meteor.settings = {};
if (process.env.METEOR_SETTINGS) {
try {
Meteor.settings = JSON.parse(process.env.METEOR_SETTINGS);
} catch (e) {
throw new Error("Settings are not valid JSON");
} catch (e) {
throw new Error("Settings are not valid JSON");
}
}
// Push a subset of settings to the client.
if (Meteor.settings && Meteor.settings.public) {
__meteor_runtime_config__.PUBLIC_SETTINGS = Meteor.settings.public;
}

0 comments on commit 4f2d725

Please sign in to comment.