原报错:
Access to XMLHttpRequest at 'http://127.0.0.1:3008/socket.io/?EIO=4&transport=polling&t=ObAPQBP' from origin 'http://127.0.0.1:5500' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
经过尝试发现使用cors库或者手动加入cors请求头无法解决,最终通过以下方法解决:‘’
const io = socketIo(server,{//设置cors
cors: {
origin: "*",
methods: ["GET", "POST"],
allowedHeaders: ["my-custom-header"],
credentials: true
}}
);