Settings.json 到 Heroku 配置
Settings.json to Heroku config
我正在向 Heroku 部署 Meteor/Node 应用程序。我的 settings.json.
中有以下几行(用于 OKGrow 分析)
{
"public": {
"analyticsSettings": {
"Google Analytics": {
"trackingId": "12345"
},
"Segment.io": {
"apiKey": "abcdef"
}
}
}
}
但是,公司政策不允许我将 settings.json 检查到源代码管理中。有没有办法使用 Heroku 配置变量来完成此操作?还有其他解决方案吗?
Heroku recommends configuring your application via environment variables:
A better solution is to use environment variables, and keep the keys out of the code. On a traditional host or working locally you can set environment vars in your bashrc
file. On Heroku, you use config vars.
还好流星will load settings from the METEOR_SETTINGS
environment variable:
When running your server directly (e.g. from a bundle), you instead specify settings by putting the JSON directly into the METEOR_SETTINGS
environment variable. If the settings object contains a key named public
, then Meteor.settings.public
will be available on the client as well as the server. All other properties of Meteor.settings
are only defined on the server. You can rely on Meteor.settings
and Meteor.settings.public
being defined objects (not undefined) on both client and server even if there are no settings specified. Changes to Meteor.settings.public
at runtime will be picked up by new client connections.
因此,只需设置您应用的 METEOR_SETTINGS
环境变量,例如通过
heroku config:set METEOR_SETTINGS="$(cat settings.json)"
在您的开发机器上,或使用 Heroku 的网络界面。
我正在向 Heroku 部署 Meteor/Node 应用程序。我的 settings.json.
中有以下几行(用于 OKGrow 分析){
"public": {
"analyticsSettings": {
"Google Analytics": {
"trackingId": "12345"
},
"Segment.io": {
"apiKey": "abcdef"
}
}
}
}
但是,公司政策不允许我将 settings.json 检查到源代码管理中。有没有办法使用 Heroku 配置变量来完成此操作?还有其他解决方案吗?
Heroku recommends configuring your application via environment variables:
A better solution is to use environment variables, and keep the keys out of the code. On a traditional host or working locally you can set environment vars in your
bashrc
file. On Heroku, you use config vars.
还好流星will load settings from the METEOR_SETTINGS
environment variable:
When running your server directly (e.g. from a bundle), you instead specify settings by putting the JSON directly into the
METEOR_SETTINGS
environment variable. If the settings object contains a key namedpublic
, thenMeteor.settings.public
will be available on the client as well as the server. All other properties ofMeteor.settings
are only defined on the server. You can rely onMeteor.settings
andMeteor.settings.public
being defined objects (not undefined) on both client and server even if there are no settings specified. Changes toMeteor.settings.public
at runtime will be picked up by new client connections.
因此,只需设置您应用的 METEOR_SETTINGS
环境变量,例如通过
heroku config:set METEOR_SETTINGS="$(cat settings.json)"
在您的开发机器上,或使用 Heroku 的网络界面。