How to check origin header in using websocket based on socket.io?

In library - 'ws' it is done like this:

var webSocketServer = new WebSocketServer.Server({ port: 8081, verifyClient: function(info, callback) { if(info.origin != null){ if(info.origin == 'http://ws-nodejs') { callback(true); }else{ callback(false); } } }); 

How to check this header in the socket.io library?

    1 answer 1

     var io=require('socket.io'); server = io(server,{ //бла бла }); server.on('connection', function (connection) { console.log(connection.handshake.headers.origin); }); 
    • Thank! But I ask you to blur my question. You need to know headers.origin до connection event. Actually this is exactly shown in the code that I attached to the question, but only this is reflected in the ws library - Yury Svetlov
    • Those. Do you telepathically want to know who will connect to you now, before he connects? - Darth
    • one
      No, not telepathically. And then telepathy? In ws this is possible. Before the connection event, you can find out all the info. - Yury Svetlov
    • Check infu of the first packet of entry on the web server - Yuri Svetlov
    • @Darth Ho-ho-ho, the wise guy OPES) - gilo1212