title: Node.js + Backbone collection json
body: <p>I have a weird behavior in my current project. I am using Node.js in the backend and Backbone.js in the frontend. My Node.js application uses express for restful services. If I navigate to the path <em>127.0.0.1:999/users</em>, everything is fine and the json data can be parsed correctly. 
  Actually my frontend looks like this:</p>
  
  <pre><code>//MODELS
  var PersonList = Backbone.Collection.extend({
    url: "http://127.0.0.1:9999/users"
  });
  
  //VIEWS
  var PersonListView = Backbone.View.extend({
    el : "#page",
    render: function(){
      var thisView = this;
      var personList = new PersonList();
      personList.fetch({
        success: function(users, xhr){
          $(thisView.el).html(users);
        },
        error: function(err)
        {
          console.log(err);
        }
      });
    }
  });
  </code></pre>
  
  <p>My backend looks as follows:</p>
  
  <pre><code>var express = require("express"); 
  var app = express();
  
  var users = [{id: 0,email: "user1@gmail.com"},
   {id: 1,email: "userxx@gmail.com"},
   {id: 2,email: "user123@gmail.com"}];
  
  app.get("/users", function(request, response){
      response.send(users);
  });
  
  app.listen(9999);
  </code></pre>
  
  <p>The fetch function does not fire the success event :(.
  Any ideas what I am doing wrong?</p>
  
  <p><strong>Solved:</strong>
  The problem is at the backend. Backbones request origin header is not accepted. Add the following code to your express application to get it work. In production make sure to store your allowed hosts in a separate configuration.</p>
  
  <pre><code>app.use(function(req, res, next){
      res.header("Access-Control-Allow-Origin", "*");
      res.header("Access-Control-Allow-Headers", "X-Requested-With, X-Authtoken, Content-Type");
      res.header("Access-Control-Allow-Methods", "HEAD, GET, POST, PUT, DELETE");
      next();
  });
  </code></pre>