title: Empty request body with POST using CORS with a node app on OpenShift
body: <p>I'm creating a simple Node app on OpenShift, using express (I'm just modifying the default example Node app of OpenShift). I want to have CORS support with it:</p>
  
  <pre><code>var cors = require('cors');
  ...
  
  /**
   *  Initialize the server (express) and create the routes and register
   *  the handlers.
   */
  self.initializeServer = function() {
      self.createRoutes();
      self.app = express();
  
      self.app.use(cors());
      self.app.use(express.json());
  
      //  Add handlers for the app (from the routes).
      for (var r in self.routes) {
          self.app.get(r, self.routes[r]);
      }
  
      self.app.post('/vote/', function (req, res) {
          // just echo back the request body
          res.json(req.body);
      });
  };
  </code></pre>
  
  <p>If I send a request from my local machine, using curl it works fine:</p>
  
  <pre><code>C:\Users\Chin\Desktop&gt;curl -H "Content-Type: application/json" -X POST -d "{\"username\":\"xyz\"}" https://bloodbrothers-chinhodado.rhcloud.com/vote/
  {"username":"xyz"}
  </code></pre>
  
  <p>However, if I send the request from another site with a different domain using jQuery, the returned body is empty:</p>
  
  <pre><code>$.ajax({
      url: "https://bloodbrothers-chinhodado.rhcloud.com/vote/",
      type: "POST",
      crossDomain: true,
      data: JSON.stringify({"username": "xyz"}),
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      success: function (response) {
          alert(response);
      },
      error: function (xhr, status) {
          alert("error");
      }
  });
  </code></pre>
  
  <p>=> the server returns <code>{}</code></p>
  
  <p>I put a <code>console.log()</code> call inside the <code>self.app.post()</code> function and indeed when the request is coming from cross-domain, the body of the request is empty.</p>
  
  <p>What did I do wrong here? The app is live so you can try the curl and ajax call yourself if you want to.</p>
  
  <p><strong>EDIT:</strong> In this case, if I make a CORS request, it does go into the <code>self.app.post('/vote/', function (req, res) {}</code> function (verified by putting in <code>console.log()</code> calls there). Does it mean that CORS is working well and the problem is not because of CORS?</p>