Socket.io doesn't set CORS header(s)

前端 未结 1 1890
萌比男神i
萌比男神i 2020-12-18 01:42


I know this question has been asked a couple of times.
However, I can\'t get any those solutions to work.
I\'m running a standard install of node.js and socket.

相关标签:
1条回答
  • 2020-12-18 01:56

    This is the syntax I had to use to get CORS working with socket.io:

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

    If it comes to it, use console.log to make sure you're entering 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';
        }
      }
    
    0 讨论(0)
提交回复
热议问题