meteor中settings.json位于程序的根目录下,里面存放一些配置信息,比如:

{
  "magicPizzaService": "Our1234API5678Key"
}

怎么用呢?

var secretPizzaAccessCode = Meteor.settings.magicPizzaService;  

如果有不同的环境,比如开发环境,生产环境,同一个变量的值是不同的,那该怎么定义呢?

{
  "public": {
    "imARidiculousHumanBeing": "butAtLeastImClean"
  },
  "private": {
    "hackTheGibson": "keyboardCoWbOyS"
  },
  "imStillServerOnly": "soDontPanic"
}

用法:

var ridiculous = Meteor.settings.public.imARidiculousHumanBeing;  
// returns "butAtLeastImClean" on the client.

var cowboys = Meteor.settings.private.hackTheGibson;  
// returns "keyboardCoWbOyS" on the server.

var dontPanic = Meteor.settings.imStillServerOnly;  
// returns "soDontPanic" on the server.

那么,怎么让meteor用到这个settings.json呢?

meteor --settings settings.json  

也可以这么用:

METEOR_SETTINGS='$(cat settings.json)' meteor  
comments powered by Disqus