Stephen Watkins
Stephen Watkins

Reputation: 25765

Accessing Meteor Settings in a Self-Owned Production Environment

According to Meteor's documentation, we can include a settings file through the command line to provide deployment-specific settings.

However, the --settings option seems to only be available through the run and deploy commands. If I am running my Meteor application on my own infrastructure - as outlined in the Running on Your Own Infrastructure section of the documentation - there doesn't seem to be a way to specify a deployment-specific settings file anywhere in the process.

Is there a way to access Meteor settings in a production environment, running on my own infrastructure?

Upvotes: 8

Views: 2341

Answers (1)

jagill
jagill

Reputation: 692

Yes, include the settings contents in an environmental variable METEOR_SETTINGS. For example,

export METEOR_SETTINGS='{"privateKey":"MY_KEY", "public":{"publicKey":"MY_PUBLIC_KEY", "anotherPublicKey":"MORE_KEY"}}'

And then run the meteor app as normal.

This will populate the Meteor.settings object has normal. For the settings above,

Meteor.settings.privateKey == "MY_KEY" #Only on server
Meteor.settings.public.publicKey == "MY_PUBLIC_KEY" #Server and client
Meteor.settings.public.anotherPublicKey == "MORE_KEY" #Server and client

For our project, we use an upstart script and include it there (although upstart has a slightly different syntax). However, if you are starting it with a normal shell script, you just need to include that export statement before your node command. You could, for example, have a script like:

export METEOR_SETTINGS='{"stuff":"real"}'
node /path/to/bundle/main.js

or

METEOR_SETTINGS='{"stuff":"real"}' node /path/to/bundle/main.js

You can find more information about bash variables here.

Upvotes: 14

Related Questions