title: Fetch API Post method is not working
body: <pre><code>fetch('http://localhost:9000/api/app/contact', {
      method: 'POST',
      headers: {
          'content-type': 'application/json'
      },
      body: JSON.stringify({
          email: this.state.email,
          contactNumber: this.state.phone,
          enquiry: this.state.msg
      })
  })
  .then(function(res) { return res.json() })
  .then(function(data) {
      alert('We will contact you shortly') 
  });
  </code></pre>
  
  <p>When I render above coding, I've encountered following error:</p>
  
  <blockquote>
    <p>Failed to load <a href="http://localhost:9000/api/app/contact" rel="nofollow noreferrer">http://localhost:9000/api/app/contact</a>: Response to
    preflight request doesn't pass access control check: No
    'Access-Control-Allow-Origin' header is present on the requested
    resource. Origin '<a href="http://localhost:8080" rel="nofollow noreferrer">http://localhost:8080</a>' is therefore not allowed
    access. If an opaque response serves your needs, set the request's
    mode to 'no-cors' to fetch the resource with CORS disabled.</p>
  </blockquote>
  
  <p>But when I tried with postman, it's successfully working. Please help me, is there any code missing in my fetch api.</p>
  
  <p>Following is postman POST request and code.</p>
  
  <p><a href="https://i.stack.imgur.com/mc8Q4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mc8Q4.png" alt="enter image description here"></a></p>
  
  <p>following code is Post request from <code>Postman</code>.</p>
  
  <pre><code>var data = JSON.stringify({
    "email": "test@gmail.com",
    "contactNumber": "0123456789",
    "enquiry": "Testing"
  });
  
  var xhr = new XMLHttpRequest();
  xhr.withCredentials = true;
  
  xhr.addEventListener("readystatechange", function () {
    if (this.readyState === 4) {
      console.log(this.responseText);
    }
  });
  
  xhr.open("POST", "http://localhost:9000/api/app/contact");
  xhr.setRequestHeader("content-type", "application/json");
  xhr.setRequestHeader("cache-control", "no-cache");
  xhr.setRequestHeader("postman-token", "d5e08b69-5f0f-8193-e021-e2c3b1bfe1a3");
  
  xhr.send(data);
  </code></pre>
  
  <p>In NodeJS server side, I've already CORS in backend.</p>
  
  <pre><code>var express = require('express'),
      controller = require('./app.controller'),
      router = express.Router(),
      cors = require('cors');
  
  var issue2options = {
    origin: true,
    methods: ['POST'],
    credentials: true,
    maxAge: 3600
  };
  
  router.post('/contact', cors(issue2options), controller.sendContactForm);
  module.exports = router;
  </code></pre>