title: Socket IO CORS issue when using a domain for server
body: <p>I am having errors from socket io when I call my server from a domain instead of server IP. This domain works for fetching data by Axios but fails and shows the error below for socket:</p>
  
  <pre><code>Access to XMLHttpRequest at 
  'https://api.alo.social/socket.io/EIO=3&amp;transport=polling&amp;t=NA9Kd2D' from 
  origin 'https://apps.alo.social' has been blocked by CORS policy: The value of the 'Access- 
  Control-Allow-Credentials' header in the response is '' which must be 'true' when the 
  request's credentials mode is 'include'. The credentials mode of requests initiated by the 
  XMLHttpRequest is controlled by the withCredentials attribute.
  
  GET https://api.alo.social/socket.io/?EIO=3&amp;transport=polling&amp;t=NA9Kd2D net::ERR_FAILED
  </code></pre>
  
  <p>My server code looks like this: </p>
  
  <pre><code>const express = require('express')
  const app = express()
  const bodyParser = require('body-parser')
  const cors = require('cors')
  const server = require('https').createServer(app)
  const getRoute = require('./routes/getRoutes')
  const postRoute = require('./routes/postRoutes')
  const socketIO = require('socket.io')
  const io = socketIO(server)
  require('dotenv').config()
  
  let port = process.env.PORT
  
  let whitelist = [
    'https://apps.alo.social',
    'https://api.alo.social'
  ]
  let corsOptions = {
      origin(origin, callback) {
      if (whitelist.indexOf(origin) !== -1 || !origin) {
      console.log('Okay', origin)
      callback(null, true)
    } else {
      console.log('Not okay', origin)
      callback(new Error('Not allowed by CORS'))
    }
   }
  }
  
  app.options('*', cors())
  app.use(cors(corsOptions));
  
  app.use(express.static('public'))
  
  app.use(bodyParser.json())
  app.use(bodyParser.urlencoded({ extended: true }))
  
  
  io.on('connection', function (socket) {
    app.use(function (req, res, next) {
      res.io = io
      next()
    })
  
    socket.on('pushMessage', function (data) {
      // console.log('pushMessage socket', data)
      io.emit('pushMessage', data)
    })
  })
  
  app.get('/', (req, res) =&gt; {
    res.send(`Server is up into port ${port}`)
  })
  
  app.use('/api/get', getRoute)
  app.use('/api/post', postRoute)
  
  app.listen(port, () =&gt; console.log(`Server is up into port ${port}`))
  
  module.exports = { app: app, server: server }
  </code></pre>
  
  <p>The client end where I am defining the socket is like:</p>
  
  <pre><code>import socketIOClient from 'socket.io-client'
  
  let serverSocket = 'https://api.alo.social/'
  
  let socket = socketIOClient(serverSocket)
  </code></pre>
  
  <p>and calling the socket like:</p>
  
  <pre><code>socket.emit('pushMessage', messageData)
  
  socket.on('pushMessage', messageData =&gt; { console.log(messageData) })
  </code></pre>
  
  <p>Can anyone help with this? </p>