I would like to set my RESTAdapter host based on the build environment.
I assume the value can be stored in config/environment.js
like this:
You define the setting like this in your config/environment.js
:
// snip
APP: {
// Here you can pass flags/options to your application instance
// when it is created
API_HOST: 'http://192.168.1.37:3000' // default setting
}
};
if (environment === 'development') {
ENV.APP.LOG_TRANSITIONS = true;
ENV.APP.API_HOST = 'http://192.168.1.37:3000'; // override
}
You can then use the setting in other files like this:
// app/adapters/application.js:
import DS from "ember-data";
export default DS.RESTAdapter.extend({
host: window.MyAppENV.APP.API_HOST
});
Replace MyApp
with your application.
You switch to a build environment with the ember --environment
option:
ember serve --environment production
or
ember build --environment development
I've not seen yet whether there is a way to provide the value dynamically, but you can provide as many environments as you want of course.
Update: Adding for completeness, and as per Weston's comment, Environments documents this functionality.