Socket.io does not set CORS headers


I know this question has been asked a couple of times. However, I cannot get any solutions for the job.
I am running a standard installation of node.js and socket.io. (From yum to Amazon EC2)
The problem is that Chrome is returning to xhr polling, and these requests require a working CORS configuration. However, I cannot get it to work. My web server is running on port 80, and node.js (socket.io) is running on port 81. I tried to force socket.io to use the origin policy, as you can see. I also tried using "*: *" as a source of no luck.
Here is my code:

var http = require('http'); var io = require('socket.io').listen(81, {origins: '*'}); io.configure( function(){ io.set('origin', '*'); }); io.set("origins","*"); var server = http.createServer(function(req, res) { io.sockets.emit("message", "test"); res.writeHead(200); res.end('Hello Http'); console.log("Message recieved!"); }); server.listen(82); io.sockets.on('connection', function(client) { console.log("New Connection"); }); 

Many thanks!

+7
source share
1 answer

This is the syntax I should have used to get CORS to work with socket.io:

 io.set( 'origins', '*domain.com*:*' ); 

If this happens, use console.log to make sure you enter this block of code in Manager.prototype.handleHandshake inside ./lib/manager.js :

  if (origin) { // https://developer.mozilla.org/En/HTTP_Access_Control headers['Access-Control-Allow-Origin'] = '*'; if (req.headers.cookie) { headers['Access-Control-Allow-Credentials'] = 'true'; } } 
+7
source

All Articles