title: cross domain CORS support for backbone.js
body: <p>I'm trying to implement a cross-domain setup for my backbone app.</p>
  
  <p>my server (express.js) is allowing cross domains and credential:</p>
  
  <pre><code>var allowCrossDomain = function(req, res, next) {
    var allowedHost = [
      'http://localhost:3001',
      'http://localhost:7357'
    ];
  
    if(allowedHost.indexOf(req.headers.origin) !== -1) {
      res.header('Access-Control-Allow-Credentials', true);
      res.header('Access-Control-Allow-Origin', req.headers.origin)
      res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
      res.header('Access-Control-Allow-Headers', 'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version');
      next();
    } else {
      res.send({auth: false});
    }
  }
  
  app.configure(function(){
      ....
      app.use(allowCrossDomain);
      ....
  });
  </code></pre>
  
  <p>my client (backbone.js) is configured to accept cross domain as well :</p>
  
  <pre><code>define(["backbone", "jquery", "underscore"], function (BB, $, _) {
    return BB.Model.extend({
  
      idAttribute: "_id",
  
      initialize: function () {
        var that = this;
  
        $.ajaxPrefilter( function( options, originalOptions, jqXHR ) {
          options.crossDomain ={
            crossDomain: true
          };
          options.xhrFields = {
            withCredentials: true
          };
        });
      }
    });
  });
  </code></pre>
  
  <p>Now when I test my code (let say a <code>POST</code> request), i have a very special behavior:</p>
  
  <pre><code>var contacts = new Contacts;
  contacts.create({'name': 'my name'});
  </code></pre>
  
  <p>The browser return this message:</p>
  
  <blockquote>
    <p>OPTIONS ... 404 (Not Found)
    jquery.js:8419</p>
  </blockquote>
  
  <p>This totally confuse me as the <code>OPTIONS</code> http method is not supported by backbone?</p>