How to pass API keys in environment variables to Ember CLI using process.env?

前端 未结 4 1866
有刺的猬
有刺的猬 2020-12-13 14:34

How do I pass environment variables from bashrc to Ember CLI. I imagine a situation where you need stripe api keys or pusher api-keys and you have them in your environment v

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-13 15:28

    I want to make sure that my API keys are not checked in. As part of the build process, I copy a local config file to the config directory and load it into environment.js

    In environment.js

    try {
      var local = require('./local_environment');
      Object.keys(local.config).forEach(function(key) {
        ENV[key] = local.config[key];
      });
    } catch(err) {
      console.log("config/local_environment.js not found");
    }
    

    In local_environment.js (not checked in, copied by build process)

    exports.config = {
      SOME_API_KEY: 'key_here'
    };
    

提交回复
热议问题