2

I have an EmberCLI app where Staging and Prod both live on the same S3 bucket, and in config/environment.js the environment variable is the same. Still I need to be able to specify different settings for the two "environments".

The surefire way to tell which app is running is by inspecting the domain of the request, but I'm having trouble intercepting that early enough to update my settings.

I've tried creating an initializer to inspect the domain and update the ENV object accordingly, but it seems it's too late in the page lifecycle to have any effect; the page has already been rendered, and my addons do not see their proper settings.

For one addon, I basically had to copy all of its code into my project and then edit the index.js file to use the proper keys based on my domain, but it's unwieldy. Is there a better way to do this? Am I trying to make an architecture work which is just ill-advised?

Any advice from those more versed in Ember would be much appreciated.

2 Answers2

0

There's not a great way to handle staging environments right now (see Stefan Penner's comment here).

That said I think you can achieve a staging environment on s3 by using ember-cli-deploy if you add a staging environment to your ember-cli-deploy config. And handle the difference between staging and production in ember-cli-build.js.

Patrick Berkeley
  • 2,206
  • 21
  • 26
  • I'm thinking at this point that we create our builds with --environment staging, and then when we promote staging to production, we can edit the Redis entry which contains the content for index.html to change the environment variable from staging to production. That way I can count on the environment variable to accurately reflect the environment and assign settings based on that like you suggest. – TwoLeggedMammal Feb 09 '16 at 18:25
0

One thing I do is reuse the production environment for both staging and production, but use shell environment variables for some of the configuration:

// config/environment.js
if (environment === 'production') {
  ENV.something = process.env.SOMETHING;
}

And then to build:

$ SOMETHING="staging-value" ember build --environment=production
James A. Rosen
  • 64,193
  • 61
  • 179
  • 261
  • That is what we do with our other apps, but because this is being served from an S3 bucket, and the same one as staging, we can't make use of environment variables. – TwoLeggedMammal Feb 09 '16 at 18:28
  • You could build twice and emit an `index-production.html` and `index-staging.html`, then use whatever sits in front of S3 (Varnish / nginx / etc.) to pick the right file for the domain. – James A. Rosen Mar 01 '16 at 21:42
  • It's a good thought. We are planning an environment migration anyway, and it looks like we'll be off of Redis/S3 soon so we're putting a hold on this. The temporary solution was to fork the addons which are environment specific and hardcode checks to look at the window.domain and set keys based on that. – TwoLeggedMammal Mar 02 '16 at 16:44