Search code examples
socket.iosubdirectorysocket.io-1.0

How do I get socket.io running for a subdirectory


I've got a proxy running that only hits my node.js server for paths that being with /mysubdir How do I get socket.io configured for this situation?

In my client code I tried:

var socket = io.connect('http://www.example.com/mysubdir');

but then I notice that the underlying socket.io (or engine.io) http requests are hitting

http://www.example.com/socket.io/?EIO=3&transport=polling&t=1410972713498-72`

I want them to hit

http://www.example.com/mysubdir/socket.io.....

Is there something I have to configure on the client and the server?


Solution

  • In my server I had to

    var io = require('socket.io')(httpServer, {path: '/mysubdir/socket.io'})`
    

    In my client I had to

    <script src="http://www.example.com/mysubdir/socket.io/socket.io.js"></script>
    

    and also

    var socket = io.connect('http://www.example.com', {path: "/mysubdir/socket.io"});`