title: No 'Access-Control-Allow-Origin' header is present on the requested resource | CORS Error
body: <p>I have a Node js, React application which works well on localhost. I recently took the code to a production environment using cPanel and now, I am getting CORS errors. These cors errors only appear in requests that are not <strong>GET</strong> requests.
  In other requests, its preflighted request passes with a 2** response, but the xhr request keeps on failing.</p>
  <p><a href="https://i.stack.imgur.com/SJH7Z.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SJH7Z.png" alt="enter image description here" /></a></p>
  <p>Below are a list of things I have done</p>
  <ul>
  <li><p>Used the cors package as below</p>
  <pre><code>
  const login_router = require(&quot;./routes/loginRouter&quot;);
  
  const app = express();
  
  const cors = require(&quot;cors&quot;);
  
  // I have made the request with and without app.options
  app.options(&quot;*&quot;, cors())
  
  // allowedDomains = [Array of allowed sites] 
  // My website is listed in the array as &quot;https://...&quot;
  app.use(cors({ origin: allowedDomains, credentials: true }));
  
  
  app.use(&quot;/api/user/login&quot;, login_router);
  
  </code></pre>
  </li>
  </ul>
  <p>I ended up with Access to XMLHttpRequest at ____ from origin ____ has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource</p>
  <ul>
  <li>Added a CORS snippet in the Nodejs <strong>.htaccess</strong> file (in case it has anything to do with apache)
  <pre><code>Header set Access-Control-Allow-Origin &quot;https://...&quot;
  Header set Access-Control-Allow-Methods &quot;GET,PUT,POST,DELETE&quot;
  Header set Access-Control-Allow-Headers &quot;Content-Type, Authorization&quot;
  
  </code></pre>
  </li>
  </ul>
  <p>It gave Access to XMLHttpRequest at ____ from origin ____ has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header contains multiple values '*, https://...', but only one is allowed.</p>
  <ul>
  <li>I also tried setting the response headers manually and still, I got the same set of errors as the first trial.</li>
  </ul>
  <p>Any help will be appreciated, Thanks!</p>