title: cross domain CORS support for express.js app
body: <p>I have an express.js application with a setup for cross-domain </p>
  
  <pre><code>var allowedHost = {
    'http://localhost:3001': true,
    'http://localhost:7357': true
  };
  
  var allowCrossDomain = function(req, res, next) {
    if(allowedHost[req.headers.origin]) {
      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(403, {auth: false});
    }
  }
  </code></pre>
  
  <p>my client (backbone.js) is configured to accept cross domain as well and everything is working fine for this part..</p>
  
  <p>now, inside my express.js app (running on port 3001) i'm trying to access simple pages like so :</p>
  
  <pre><code>app.get('/app', function(req, res, next){
    return res.render("" + __dirname + "/views/app", {
      title: 'hello world'
    });
  });
  </code></pre>
  
  <p>if i call the url localhost:3001/app for example i have 403 error because the req.headers.origin is undefined, Do you have any idea ?</p>
  
  <p>How should i tell my normal express.js routes to cope with the cross domain checking ?</p>
  
  <p>Any help on this issue will be really appreciated ;-)</p>