Socket.io gives CORS error even if I allowed cors it on server

后端 未结 5 1982
名媛妹妹
名媛妹妹 2020-12-17 15:31

My node server and client are running on different ports(3001,5347 respectively). On client I had used,

var socket = io(\'http://127.0.0.1:3001\');
         


        
5条回答
  •  清歌不尽
    2020-12-17 15:51

    Following code helped:

    const PORT = process.env.PORT || 4000;
    const app = express();
    const server = app.listen(PORT, () => {
        console.log(`Server running on port ${PORT}`);
    });
    const io = socket(server);
    

提交回复
热议问题