socket.io cors 1

socket.io cors

const io = require("socket.io")(httpServer, 
  { 
  cors: {    
    origin: "*",    
    methods: ["GET", "POST"]  
  }});

Here is what the above code is Doing:
1. We’re importing the http module, which is a built-in Node module for creating HTTP servers.
2. We’re importing the socket.io module, which is a library for enabling real-time, bidirectional, and event-based communication between the browser and the server.
3. We’re creating an HTTP server using the http module.
4. We’re creating a socket.io server using the socket.io module.
5. We’re passing the HTTP server to the socket.io module.

Similar Posts