在自有生产环境中访问流星设置 [英] Accessing Meteor Settings in a Self-Owned Production Environment

查看:79
本文介绍了在自有生产环境中访问流星设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据Meteor的文档,我们可以通过命令行包含一个设置文件,以提供特定于部署的设置.

但是,--settings选项似乎只能通过rundeploy命令使用.如果我在自己的基础架构上运行Meteor应用程序-如文档-似乎没有一种方法可以在过程中的任何地方指定特定于部署的设置文件.

是否可以在自己的基础架构上运行的生产环境中访问Meteor设置?

解决方案

是的,将设置内容包括在环境变量METEOR_SETTINGS中.例如,

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

然后正常运行流星应用程序.

这将填充Meteor.settings对象正常.对于上述设置,

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

对于我们的项目,我们使用 upstart 脚本并将其包含在其中(尽管新贵的语法略有不同).但是,如果要使用普通的shell脚本启动它,则只需要在node命令之前包括该export语句即可.例如,您可以使用以下脚本:

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

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

您可以在此处找到有关bash变量的更多信息.

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?

解决方案

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.

这篇关于在自有生产环境中访问流星设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆