title: How to fix cors policy problem "It does not have HTTP ok status" in Socket.io
body: <p>I'm setting up socket.io server, and there is a problem with a cors policy . For example: If script uses a get request everything works, but while connecting to socket.io server this error shows on console</p>
  
  <blockquote>
    <p>Access to XMLHttpRequest at '<a href="https://ser.domain.xyz/iotCloud/?EIO=3&amp;transport=polling&amp;t=MdKfMsN" rel="nofollow noreferrer">https://ser.domain.xyz/iotCloud/?EIO=3&amp;transport=polling&amp;t=MdKfMsN</a>' from origin '<a href="https://www.domain.xyz" rel="nofollow noreferrer">https://www.domain.xyz</a>' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.</p>
  </blockquote>
  
  <p>I think it is problem with socket.io. I tried everything but nothing worked. </p>
  
  <pre class="lang-js prettyprint-override"><code>
  var server = express();
  
  var app = require('http').Server(server);
  
  const io = new socket(app, {
    path   : "/iotCloud",
    origins: 'https://www.domain.xyz'
  })
  
  server.use(function(req, res, next){
    res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
    res.header('Access-Control-Allow-Headers', 'Access-Control-Allow-Origin,*');
    res.header('Access-Control-Allow-Credentials', true);
    res.header('Access-Control-Allow-Origin', 'https://www.projectann.xyz');
    next();
  })
  
  </code></pre>
  
  <p>I also tried this instead of server.use</p>
  
  <pre class="lang-js prettyprint-override"><code>
  
  var corsOptions = {
    origin: 'https://www.domain.xyz',
    credentials: true,
    methods: "GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS",
    preflightContinue: true,
    optionsSuccessStatus: 204,
  }
  
  server.use(cors(corsOptions))
  
  </code></pre>
  
  <p>Client - ServiceWorker</p>
  
  <pre class="lang-js prettyprint-override"><code>importScripts('../cdn/js/socket.io.js');
  var es = {};
       es.socket = io("https://ser.domain.xyz",{
          transportOptions: {
              polling: {
                  extraHeaders: {
                      server: "AnnIoT",
                      "loginObject": JSON.stringify(m.data)
                    }
              }
          },
          secure: true,
          rejectUnauthorized: false,
          path: '/iotCloud'
        });
  
  
  </code></pre>
  
  <p>I searched everywhere stack,github and even other languages that saw this error. </p>