EmberCLI - Determining environment from request early in the page lifecycle

160 views Asked by At

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

There are 2 answers

1
Patrick Berkeley On

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.

3
James A. Rosen On

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