12

I'm trying to configure the adapter in my Ember CLI app to use a different host based on the environment. In dev, I want it to be the default current host (letting me customize it via the --proxy option, but in production I know it will be http://some.url.

I tried importing my ENV into my application adapter:

// adapters/application.js
import DS from "ember-data";
import ENV from "../../config/environment";

export default DS.ActiveModelAdapter.extend({
  host: ENV.host
});

but I'm getting an error that tmp/tree_merger../config/environment.js doesn't exist.

Sam Selikoff
  • 12,366
  • 13
  • 58
  • 104
  • 1
    possible duplicate of [Using ENV values in ember-cli app during build](http://stackoverflow.com/questions/25188263/using-env-values-in-ember-cli-app-during-build) – Leeft Aug 11 '14 at 19:06

2 Answers2

21

You are pretty close. You should only going up one step in the directory tree (when you are in a route, controller, etc you need to go up two).

// adapters/application.js
import DS from "ember-data";
import ENV from "../config/environment";

export default DS.ActiveModelAdapter.extend({
  host: ENV.host
});

The documentation is here.

Note you probably shouldn't be defining your own variables directly on ENV. Use ENV.APP in config/environment.js

var ENV = {
  ...
  APP: {
    // Here you can pass flags/options to your application instance
    // when it is created
    host: 'some_host'
  }
};

And access it the same way

import ENV from '../config/environment';

export default DS.ActiveModelAdapter.extend({
  host: ENV.APP.host
});
Chris Hayes
  • 127
  • 11
andorov
  • 4,197
  • 3
  • 39
  • 52
  • Thanks for updating the answer, I noticed this after the update that let you `import` the ENV but forgot to change this answer. – Sam Selikoff Oct 28 '14 at 17:21
0

This seems to work

// adapters/application.js
import DS from "ember-data";

export default DS.ActiveModelAdapter.extend({
  host: window.MyAppENV.host
});

though I'm not sure if it's the best method.

Sam Selikoff
  • 12,366
  • 13
  • 58
  • 104