Environment-based host in Ember CLI app

懵懂的女人 提交于 2019-12-04 02:26:51
andorov

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
});

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!