Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 955
Stephen Watkins Avatar asked Apr 18 '13 18:04

Stephen Watkins


1 Answers

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.

like image 152
jagill Avatar answered Sep 22 '22 07:09

jagill