<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: OlammieAO</title>
    <description>The latest articles on DEV Community by OlammieAO (@olammieao).</description>
    <link>https://dev.to/olammieao</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F873712%2Fc2fc1853-acbe-47dc-8b96-ad4d10e4eab7.png</url>
      <title>DEV Community: OlammieAO</title>
      <link>https://dev.to/olammieao</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/olammieao"/>
    <language>en</language>
    <item>
      <title>Reactjs NodeJS Cors Request Not Succeeded Errors</title>
      <dc:creator>OlammieAO</dc:creator>
      <pubDate>Tue, 07 Jun 2022 11:56:59 +0000</pubDate>
      <link>https://dev.to/olammieao/reactjs-nodejs-cors-request-not-succeeded-errors-f2</link>
      <guid>https://dev.to/olammieao/reactjs-nodejs-cors-request-not-succeeded-errors-f2</guid>
      <description>&lt;p&gt;My reactjs website runs on https and my NodeJS server is https but I got error calling the NodeJS api from reactjs website. Both ReactJS website and NodeJS api deployed on the same linux VPS server, my database is on a remote but the connection is fine as I am not getting database connection error but i got cors errors like below:&lt;/p&gt;

&lt;p&gt;Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at &lt;a href="https://localhost:8184/api/v1/signin"&gt;https://localhost:8184/api/v1/signin&lt;/a&gt;. (Reason: CORS request did not succeed). Status code: (null).&lt;/p&gt;

&lt;p&gt;My NodeJS that started the https server enable cors and it allowed cross origin. See my NodeJS&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const cors = require('cors')({
   origin: 'https://mydomaindotcom'
});


const allowCrossDomain = function (req, res, next) {
    res.header('Access-Control-Allow-Origin', '*');
    res.header('Access-Control-Allow-Methods', 'POST, GET, PUT,PATCH, DELETE, OPTIONS, ');
    res.header('Access-Control-Allow-Credentials', false);
    res.header('Access-Control-Max-Age', '86400');
    res.header('Access-Control-Allow-Headers', 'Authorization, X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept');
    next();
};
app.use(allowCrossDomain);
// Error logger
app.use(logger('dev', {
    skip: function (req, res) { return res.statusCode &amp;lt; 400 },
    stream: fileWriter
}))
app.use(logger('dev'));
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.use(cors);
app.use(fileUpload());
app.use("/api/v1", routes);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In my ReactJS package.json file i have my domain as homepage like below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"homepage": "https://mydomain",
"Hostname": "https://mydomain",
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Please help on this cors errors, it has taken enough sweat on my face.&lt;/p&gt;

</description>
      <category>react</category>
      <category>node</category>
      <category>linux</category>
    </item>
  </channel>
</rss>
