首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ember模型主机适配器不覆盖幻象

Ember模型主机适配器不覆盖幻象
EN

Stack Overflow用户
提问于 2016-10-20 07:01:28
回答 1查看 237关注 0票数 0

我正在使用Ember-cli-mirage来模拟数据。我想慢慢地集成生产应用程序接口的一部分,它位于我的本地机器http://localhost:8000上。Ember docs tell me说,我应该能够设置适配器,这样我就可以为每个型号设置不同的主机。

我有一个customer模型,并设置了ember-cli-mirage,它成功地为数据提供了服务。客户模型是我想拆分到localhost:8000的第一个模型。

我已经使用以下内容设置了adapters/customer.js:

代码语言:javascript
复制
import DS from 'ember-data';

export default DS.RESTAdapter.extend( {
  host: 'http://localhost:8000',
  namespace: 'api/v1'
});

但是当我打电话的时候,我得到了一个错误:

代码语言:javascript
复制
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服务器发出请求:

代码语言:javascript
复制
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的一个变体作为潜在的解决方法。但我不明白为什么幻影不接受适配器覆盖。

EN

回答 1

Stack Overflow用户

发布于 2016-10-20 08:12:23

我应该再读一遍这本书的海市话文档。有一个passthrough function可以让mirage绕过mirage将某些请求传递给Ember:

代码语言:javascript
复制
// 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');

}

为了在我的应用程序适配器中实现这一点,我添加了:

代码语言:javascript
复制
// app/adapters/application.js
import DS from 'ember-data';

export default DS.RESTAdapter.extend({
  host: 'http://localhost:8000',
  namespace: 'api/v1'
});

如果这对你有任何帮助,请随意给这个答案投赞成票:)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40142862

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档