Categories
JavaScript Answers

How to fix Socket.io and Node.js Cross-Origin request blocked?

Spread the love

To fix Socket.io and Node.js Cross-Origin request blocked, we add a cors option into the server.

For instance, we write

const io = require("socket.io")(server, {
  cors: {
    origin: "*",
  },
});

to set the cors.origin property to allow connection from all origins.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *