问题描述
我正在尝试在Ember CLI应用程序中将适配器配置为根据环境使用其他主机。在开发人员中,我希望它成为当前的默认主机(让我通过-proxy
选项对其进行自定义,但是在生产环境中,我知道它将是 http://some.url
。
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
.
我尝试将 ENV
导入我的应用程序适配器:
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
});
但是我收到一个错误,该错误是 tmp / tree_merger ../ config /environment.js
不存在。
but I'm getting an error that tmp/tree_merger../config/environment.js
doesn't exist.
推荐答案
您已经很接近了,应该只去
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
});
文档为。
请注意,您可能不应该直接在ENV上定义自己的变量。在 config / environment.js
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'
}
};
并以相同的方式访问它
import ENV from '../config/environment';
export default DS.ActiveModelAdapter.extend({
host: ENV.APP.host
});
这篇关于Ember CLI应用程序中基于环境的主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!