3

I'm using Ember.js 2.5.0 and it seems at the moment Ember is limited to the three environments development, test and production. How can I add some other env like as for example staging?

I have a staging server so we can test our app and I want to use different configurations there (than the development one). Any workaround to do that?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Eki Eqbal
  • 5,779
  • 9
  • 47
  • 81

2 Answers2

5

I had the same problem and I've resolved it editing two files environment.js and ember-cli-build.js

In environment.js I've added another IF to set values for the new environment:

if(environment === "stage") {
  ENV.APP.xxxx = 'stage value'
}

In ember-cli-build.js I've customized how the fingerprint is enabled or not. You can do the same for other settings.

module.exports = function(defaults) {
  var fingerprintEnabled = false;
  var env = process.env.EMBER_ENV || 'development';
  switch (env) {
    case 'development':
      fingerprintEnabled = false;
      break;
    case 'test':
      fingerprintEnabled = false;
      break;
    case 'production':
    case 'stage':
      fingerprintEnabled = true;
      break;
  }
  var app = new EmberApp(defaults, {
    fingerprint: {
      enabled: fingerprintEnabled,
      exclude: [...]
    }
    // Add options here
  });

When building the app I pass the proper environment flag:

ember build --environment=stage
GUL
  • 1,175
  • 1
  • 13
  • 22
  • Doesn't work for me. Could you explain what the `fingerprint` is for? Do you inherit all production settings for staging somehow? – JoannaFalkowska Nov 16 '16 at 11:18
  • I mean, I get that fingerprint is only one setting. But is there a way to inherit all unchanged settings from production? – JoannaFalkowska Nov 16 '16 at 12:08
  • No, I don't inherit production settings, I had only the need to override the fingerprint setting. – GUL Nov 17 '16 at 13:55
2

As it states in ember-cli documentation, ember-cli is limited to three environments at the moment.

The best workaround at this stage is to use something like ember-cli-dotenv. Have a look specifically at this part of the readme.

Pasted here for easier reference:

// ember-cli-build.js

module.exports = function(defaults) {
  var app = new EmberApp(defaults, {
    dotEnv: {
      clientAllowedKeys: ['DROPBOX_KEY'],
      path: './path/to/.env'
    }
  });

  return app.toTree();
};

Where DROPBOX_KEY can now be anything according do your .env.

Related SO question.

Community
  • 1
  • 1
TameBadger
  • 1,580
  • 11
  • 15
  • Thanks for your willing to help @TameBadger. Is that a common practice tho? I mean Ember already provides `environment.js` to handle this, would it be good to use `dotenv` in this case? no simpler solution in this case? – Eki Eqbal May 09 '16 at 06:46
  • Have a look at https://github.com/ember-cli/ember-cli/issues/660 and https://github.com/ember-cli/ember-cli/issues/3176 for related discussions and also https://github.com/ember-cli/ember-cli/pull/1520 – TameBadger May 09 '16 at 06:49