How I use Ember-cli with http-mock?

Hello I’m new in ember.js

I try to use http-mock, so I typed belows.

ember g http-mock destinations

I already have destination model, adapter, route.

My server/mocks/destinations.js

  destinationsRouter.get('/', function(req, res) {
    "destinations": [{
      id: 1,
      title: "Destination 1"
    }, {
      id: 2,
      title: "Destination 2"

and, my app/routes/destinations.js

import Ember from 'ember';

export default Ember.Route.extend({
  model: function() {
    // return'destination');
    return [{
        id: 1,
        title: "Destination 1"
      }, {
        id: 2,
        title: "Destination 2"
      }, {
        id: 3,
        title: "Destination 3"
      }, {
        id: 4,
        title: "Destination 4"

I tested remove comment return‘destination’);

console print out

GET http://localhost:4200/destinations 404 (Not Found)

I think my app didn’t have address /destinations because {
    this.route('destinations', { path: '/' },function(){
    this.route('new', { path: '/new' });
    this.route('edit', { path: '/edit/' });
    this.route('destination', { path: '/'});

I cant find example of http-mock.

how to assemble this situation? I want to use http-mock.


By default, the file generated by http-mock will be served on /api/destinations. So you need to inform Ember Data to fetch data from that url (instead of http://localhost:4200/destinations). You can do that by setting the namespace parameter in the application adapter:

// app/adapter/application.js
import DS from 'ember-data';

export default DS.RESTAdapter.extend({
  namespace: 'api'

Hope it works :smile:

Thanks @leojpod. http://localhost:4200/api/destinations actually gives me

{"destinations":[{"id":1,"title":"Destination 1"},    {"id":2,"title":"Destination 2"}]} 

and I remove destinations path ‘/’, remove return‘destination’)

actually I connected successfully http://localhost:4200/destinations

finally I really need to get data of ( http://localhost:4200/api/destinations ) .

why‘destination’) not working?

This is what your API is supposed to send to your Ember-app. So far so good.

Then I think you are mixing things up between the Ember configuration and the Ember Data connection with a backend.

Routes and path you defined in your Ember application (app/router.js) defines URLs associated with the Ember app. It doesn’t inform Ember Data of where it should connect to fetch the models: that is part of the adapter’s job.

What is this error?

2015-02-26 22:13 ember[4252] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-21)
Livereload server on port 35729
2015-02-26 22:13 ember[4252] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-21)

I just typed ember serve in terminal…

** Addtional ** I found this problem is associated with watchman.

remove watchman’s watch list

watchman shutdown-server
rm $TMPDIR/.watchman.$USER.state

finally I solved FSEvents.framework error, but It’s not completed answer.

I found this post. I think this problems occured by live-reload action…

Hmm but those are not linked to the http-mock usage anymore are they?

hello @leojpod :smiley: I think this problem related with watchman… I open issue about this problem.

I found same issue for me.

Shutdown ember-cli and restart Sublime Text. :smile: