title: Socket.io + Node.js Cross-Origin Request Blocked
body: <p>I'm using node and socket.io to write a chat application. It works fine on Chrome but mozilla gives an error to enable the Cross-Origin Requests.</p>
  
  <blockquote>
    <p>Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at <a href="http://waleedahmad.kd.io:3000/socket.io/?EIO=2&amp;transport=polling&amp;t=1401964309289-2&amp;sid=1OyDavRDf4WErI-VAAAI" rel="noreferrer">http://waleedahmad.kd.io:3000/socket.io/?EIO=2&amp;transport=polling&amp;t=1401964309289-2&amp;sid=1OyDavRDf4WErI-VAAAI</a>. This can be fixed by moving the resource to the same domain or enabling CORS.</p>
  </blockquote>
  
  <p>Here's my code to start node server.</p>
  
  <pre><code>var express = require('express'),
      app = express(), 
      server = require('http').createServer(app),
      io = require('socket.io').listen(server),
      path = require('path');
  server.listen(3000);
  
  app.get('/', function(req, res) {
      res.sendfile(__dirname + '/public/index.html');
  });
  </code></pre>
  
  <p>On the client side.</p>
  
  <pre><code>var socket = io.connect('//waleedahmad.kd.io:3000/');
  </code></pre>
  
  <p>Script tag on HTML page.</p>
  
  <pre><code>&lt;script type="text/javascript" src="//waleedahmad.kd.io:3000/socket.io/socket.io.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>I'm also using .htaccess file in the app root directory. (waleedahmad.kd.io/node).</p>
  
  <pre><code>Header add Access-Control-Allow-Origin "*"
  Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
  Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
  </code></pre>