mardi 20 décembre 2016

emberjs mock-server adapters api

I am using http-mock server to display some data in my project. The mock server is named books.js and it has following:

var books= [
{
  id: 1,
  title: 'Good',
  description: "This is good"
},
{
  id: 2,
  title: 'Bad',
  description: "This is bad"
},
];

booksRouter.get('/', function(req, res) {
res.send({
  'books': books
 });
});

I have a model named 'book' which has:

import DS from 'ember-data';

export default DS.Model.extend({
    title: DS.attr(),
    description: DS.attr()
});

My adapters have:

import DS from 'ember-data';

export default DS.JSONAPIAdapter.extend({
    namespace: 'api'
});

And my routes is named books.js and have the following code:

import Ember from 'ember';

export default Ember.Route.extend({
    model: function() {
        return this.get('store').findAll('book');
    }
});

Everything seems correct but when I try to load the link localhost:4200/books (which is the right route) I get this error:

GET xhr localhost:4200/api/book  404 not found
Error while processing route: books    Ember Data Request GET  /api/book returned 404

The api is displayed when I check localhost:4200/api/books. What I need here is to point to /api/books and not /api/book

What is causing this error? and what might be the solution for this? I would appreciate any help that would help me resolve this issue. I am stuck in the project because of this and could not find help anywhere else. I am using ember version 2.10.0.




Aucun commentaire:

Enregistrer un commentaire