title: Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource (Reason: CORS request did not succeed)
body: <p>How to set cors in node.js for socket.io v2.2.0?(ngx-socket-io:3.4.0).</p>
  <p>Tried to set like following but not able to make connection:</p>
  <pre><code>var http = require('http');
  var {app,io} = require('../router/nexusservices.router');
  var wfwsdk = require('wfw-sdk');
  var Service = wfwsdk.getServiceConfigurations('nexusservices');
  
  if (Service) {
   var port = normalizePort(Service.port);
   
    // fix Cross-Origin Request Blocked issue
   app.use(function (req, res, next) {
       res.header(&quot;Access-Control-Allow-Origin&quot;, &quot;*&quot;);
       res.header(&quot;Access-Control-Allow-Headers&quot;, &quot;*&quot;);
       res.header(&quot;Access-Control-Allow-Methods&quot;, &quot;*&quot;);
       if (req.method === &quot;OPTIONS&quot;) {
          return res.status(200).end();
       }
       next();
   });
  
   app.set('port', port);
   /**
   * Create HTTP server.
   */
   var server = http.createServer(app);
  
   server.listen(port);
   server.on('error', onError);
   server.on('listening', onListening);
    
   io.attach(server);
   io.set('origins', '*:*'); //////// not working
  </code></pre>