mardi 28 avril 2015

How can I return a well formatted 201 with Express?

I'm trying to build todoMVC with ember-cli using the DS.RESTAdapter and express to mock out the calls. The issue I'm getting is that when I try to save a new todo I see this error in the console:

SyntaxError: Unexpected end of input
    at Object.parse (native)
    at jQuery.parseJSON (http://localhost:4200/assets/vendor.js:8717:22)
    at ajaxConvert (http://localhost:4200/assets/vendor.js:9043:19)
    at done (http://localhost:4200/assets/vendor.js:9461:15)
    at XMLHttpRequest.jQuery.ajaxTransport.send.callback (http://localhost:4200/assets/vendor.js:9915:8)

I'm pretty sure the issue is that when I call save() on the newly created model, it is sending a post request to / which express is replying to with this:

 todosRouter.post('/', function(req, res) {
    res.status(201).end();
  });

Here's the create action in Ember that's creating the todo:

actions:
    createTodo: ->
      return unless title = @get('newTitle')?.trim()

      @set('newTitle', '')
      @store.createRecord('todo',
        title: title
        isCompleted: false
      ).save()

Any help would be greatly appreciated. I'm new to express and not sure why jquery doesn't like the 201 it is returning.




Aucun commentaire:

Enregistrer un commentaire