Socket.io - How to get client URL request on server side?

后端 未结 2 954
萌比男神i
萌比男神i 2021-02-10 01:18

In my app.js (server) I need to know from where (URL) the request came.

Currently, I\'m passing the URL as parameter from the client:

socket.emit(\'reque         


        
相关标签:
2条回答
  • 2021-02-10 01:35

    To obtain the connection URL

    io.sockets.on('connection', function(socket) {
    
        console.log("url: " + socket.handshake.url);
    
    });
    

    This will return something like: url: /socket.io/1/?t=1407807394827

    0 讨论(0)
  • 2021-02-10 01:40

    For the entire URL you could use socket.handshake.headers.referer

    io.on('connect', (socket) => {
         console.log(socket.handshake.headers.referer);
    });
    
    0 讨论(0)
提交回复
热议问题