title: Socket.io cors error by using node, react and socket.io
body: <p>We are using CORS to allow all origins </p>
  
  <pre><code>app.use(cors());
  </code></pre>
  
  <p>server running on port 4000, and client running on 3000</p>
  
  <p>here is my <strong>server.js</strong> code </p>
  
  <pre><code>const cors = require("cors");
  const http = require("http");
  const socketIO = require("socket.io");
  
  app.use(cors());
  
  const port = process.env.PORT || process.env.DEFAULT_PORT;
  console.log("port: ", port);
  app.listen(port, () =&gt; {
    console.log(`App listening at ${port}...`);
  });
  
  const server = http.createServer(app);
  
  const io = new socketIO(server, {
    transports: ["websocket"],
  
  });
  </code></pre>
  
  <p>React js code</p>
  
  <pre><code>  constructor(props) {
      super(props);
      try {
        this.socket = io("http://localhost:4000", { transport: ["websocket"] });
  
        this.socket.on("Chat-event", data =&gt; {
          console.log("socketdata", data);
        });
      } catch (error) {
        console.log("hiterror", error)
      }
    }
  </code></pre>
  
  <p>I am continuously getting this error on the client side after allowing origin for all.</p>
  
  <p><strong>Access to XMLHttpRequest at '<a href="http://localhost:4000/socket.io/?EIO=3&amp;transport=polling&amp;t=Mv-SSIc" rel="nofollow noreferrer">http://localhost:4000/socket.io/?EIO=3&amp;transport=polling&amp;t=Mv-SSIc</a>' from origin '<a href="http://localhost:3000" rel="nofollow noreferrer">http://localhost:3000</a>' has been blocked by CORS policy: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute</strong></p>