mock-socket
mock-socket copied to clipboard
Socket.IO -- catching path on connection
In Socket.IO, it's possible to specify the path when initializing socket:
// io mocked with SocketIO from mock-server
const socket = io ('localhost:8080', {
path: '/hello/world',
}
// Results in connection to localhost:8080/hello/world
However, when connecting to mock-socket server, this path is truncated:
const serverPathInUrl = new Server ('localhost:8080/hello/world')
serverPathInUrl.on ('connection', socket => {
console.log ('This never gets called')
})
const serverPathSeparate = new Server ('localhost:8080')
serverPathSeparate.on ('connection', socket => {
console.log (socket.url)
// 'localhost:8080'
})
const serverPathSpecific = new Server ('localhost:8080' {
path: '/hello',
})
serverPathSeparate.on ('connection', socket => {
// Joyfully accepts connections from other paths
})
For an application that employs multiple sockets on the same host but different paths, what can be done to retrieve the path that was used for connection, or to only accept connections on given path?