<h2>This is different from other cors related questions</h2>
<p>I am running my node backend-api on <strong>microservices on kubernetes deployed on Digitalocean</strong>. I have literally read all the blogs/forums related to this issue and haven't found any solution (specifically the ones related to Digitalocean).</p>
<p>I am unable to connect to the cluster <em>via React application</em> running on '<strong>localhost:3000</strong>' or anywhere outside the kubernetes cluster.</p>
<p>It is giving me below error:</p>
<pre><code>Access to XMLHttpRequest at 'http://cultor.dev/api/users/signin' 
from origin 'http://localhost:3000' has been blocked by 
CORS policy: Response to preflight request doesn't pass access 
control check: Redirect is not allowed for a preflight request.
</code></pre>
<p>The kubernetes cluster's loadbalancer is listening on <strong>&quot;cultor.dev&quot;</strong> which is set as a local domain in <strong>/etc/hosts</strong>.
<strong>I am able to make it work using Postman!</strong></p>
<blockquote>
<p><strong>NOTE:</strong>
I have tried using cors package as well, it won't help. Also, it works fine if I run this react app <strong>inside of the kubernetes cluster</strong> which I do not want.</p>
</blockquote>
<blockquote>
<p><strong>Ingress nginx config</strong> (tried using annotations mentioned on the official website):</p>
</blockquote>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata: 
    name: ingress-service 
    ## this tells ingress to pick up the routing rules mentioned in this config
    annotations: 
        nginx.ingress.kubernetes.io/default-backend: ingress-nginx-controller
        kubernetes.io/ingress.class: nginx 
        ## tells ingress to check for regex in the config file
        nginx.ingress.kubernetes.io/use-regex: 'true'
        # nginx.ingress.kubernetes.io/enable-cors: 'true'
        # nginx.ingress.kubernetes.io/cors-allow-methods: &quot;PUT, GET, POST, OPTIONS&quot;
        # nginx.ingress.kubernetes.io/cors-allow-origin: &quot;*&quot;
        # nginx.ingress.kubernetes.io/cors-max-age: 600
        # certmanager.k8s.io/cluster-issuer: letsencrypt
        # kubernetes.io/ingress.class: nginx
        # service.beta.kubernetes.io/do-loadbalancer-enable-proxy-protocol: &quot;true&quot;
</code></pre>
<blockquote>
<p><strong>One of the microservices config</strong> (tried cors package as well):</p>
</blockquote>
<pre class="lang-js prettyprint-override"><code>// APP SETTINGS
app.set('trust proxy', true);
app.use(json());
app.use((req, res, next) =&gt; {
  res.header('Access-Control-Allow-Origin', '*');
  res.header('Access-Control-Allow-Headers', '*');
  res.header('Access-Control-Request-Headers', '*');
  if (req.method === &quot;OPTIONS&quot;) {
    res.header('Access-Control-Allow-Methods', '*');
    return res.status(200).json({});
  }
  next();
});
</code></pre>

Karan Kumar
<p>Okay, after alot of research and with the help of the other answers I did the following:</p>
<ol>
<li>I changed the request to the backend (from the client side) to <strong>https</strong> instead of <strong>http</strong>. This fixed the error <code>Redirect is not allowed for a preflight request</code></li>
<li>I changed the config <strong>ingress nginx</strong> config to get rid of the error <code>multiple values in Access-Control-Allow-Origin</code> :</li>
</ol>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    nginx.ingress.kubernetes.io/default-backend: ingress-nginx-controller
    kubernetes.io/ingress.class: nginx
    ## tells ingress to check for regex in the config file
    nginx.ingress.kubernetes.io/use-regex: &quot;true&quot;
    nginx.ingress.kubernetes.io/configuration-snippet: |
      add_header Access-Control-Allow-Methods &quot;POST, GET, OPTIONS&quot;;
      add_header Access-Control-Allow-Credentials true;
    nginx.ingress.kubernetes.io/enable-cors: &quot;true&quot;
    nginx.ingress.kubernetes.io/cors-allow-methods: &quot;PUT, GET, POST, OPTIONS&quot;
</code></pre>
<p>I hope it helps others as well.</p>
