我正在使用Ember-cli-mirage来模拟数据。我想慢慢地集成生产应用程序接口的一部分,它位于我的本地机器http://localhost:8000上。Ember docs tell me说,我应该能够设置适配器,这样我就可以为每个型号设置不同的主机。
我有一个customer模型,并设置了ember-cli-mirage,它成功地为数据提供了服务。客户模型是我想拆分到localhost:8000的第一个模型。
我已经使用以下内容设置了adapters/customer.js:
import DS from 'ember-data';
export default DS.RESTAdapter.extend( {
host: 'http://localhost:8000',
namespace: 'api/v1'
});但是当我打电话的时候,我得到了一个错误:
Mirage: Error: Your Ember app tried to GET 'http://localhost:8000/api/v1/customers',
but there was no route defined to handle this request.
Define a route that matches this path in your
mirage/config.js file. Did you forget to add your namespace?我的header检查器显示客户正在向mirage服务器发出请求:
Request URL:http://localhost:6543/customers
Request Method:GET
Status Code:304 Not Modified
Remote Address:[::1]:6543我怀疑这与我的配置/环境.js设置有关,所以我正在寻找https://github.com/samselikoff/ember-cli-mirage/issues/497#issuecomment-183458721的一个变体作为潜在的解决方法。但我不明白为什么幻影不接受适配器覆盖。
发布于 2016-10-20 08:12:23
我应该再读一遍这本书的海市话文档。有一个passthrough function可以让mirage绕过mirage将某些请求传递给Ember:
// mirage/config.js
import Mirage from 'ember-cli-mirage';
export default function() {
this.urlPrefix = 'http://localhost:8000';
this.namespace = '/api/v1';
// Requests for customers
this.get('/customers');
this.get('/customers/:id');
this.post('/customers');
this.del('/customers/:id');
this.patch('/customers/:id');
// Passthrough to Django API
this.passthrough('/customers');
}为了在我的应用程序适配器中实现这一点,我添加了:
// app/adapters/application.js
import DS from 'ember-data';
export default DS.RESTAdapter.extend({
host: 'http://localhost:8000',
namespace: 'api/v1'
});如果这对你有任何帮助,请随意给这个答案投赞成票:)
https://stackoverflow.com/questions/40142862
复制相似问题