Accessing Meteor Settings in a Self-Owned Production Environment

删除回忆录丶 提交于 2019-12-03 06:20:52

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/16090281/accessing-meteor-settings-in-a-self-owned-production-environment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!