title: socket.io connect failed on production, working in localhost
body: <p>I have this in server.js</p>
  
  <pre><code>//socket io config
  const server = require('http').createServer(app)
  const io = require('socket.io')(server)
  io.on('connection', function (socket) {
    socket.on('SOCKET_COMMENT_RECEIVED', ({ notification }) =&gt; {
      io.emit(`SOCKET_COMMENT_RECEIVED`, notification)
    })
    //and many more
  })
  </code></pre>
  
  <p>In my client (react)</p>
  
  <pre><code>import io from 'socket.io-client'
  const socket = io('localhost:3001') // working in localhost
  </code></pre>
  
  <p>in my prod I do this checking</p>
  
  <pre><code>let socket = io('localhost:3001')
  if(process.env.NODE_ENV === 'production') { socket = 
    io('https://api.example.com:3001') 
  }
  </code></pre>
  
  <p>Why is it so? I don't think it's cors issue because I already did</p>
  
  <pre><code>app.use(cors({
    origin: true,
    credentials: true
  }))
  </code></pre>
  
  <p>my package.json deps</p>
  
  <pre><code>"socket.io": "^2.1.1",
  "socket.io-client": "^2.1.1",
  </code></pre>