使用 METEOR SETTINGS 指定 app 参数

METEOR_SETTINGS 环境变量可以接受 JSON 对象,并将在 Meteor.settings 对象中公开该对象。首先,使用一些配置信息将 settings.json 添加到你的应用根目录。

{
  "public":{
    "ga":{
      "account":"UA-XXXXXXX-1"
    }
  }
}

然后,你需要使用设置文件启动应用程序。

# run your app in local development mode with a settings file
meteor --settings settings.json

# or bundle and prepare it as if you're running in production
# and specify a settings file
meteor bundle --directory /path/to/output
cd /path/to/output
MONGO_URL="mongodb://127.0.0.1:27017" PORT=3000 METEOR_SETTINGS=$(cat /path/to/settings.json) node main.js

然后可以从 Meteor.settings 访问这些设置并在你的应用程序中使用。

Meteor.startup(function(){
  if(Meteor.isClient){
    console.log('Google Analytics Account', Meteor.settings.public.ga.account);
  }
});