How do I get socket.io running for a subdirectory

Drew LeSueur picture Drew LeSueur · Sep 17, 2014 · Viewed 10.6k times · Source

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?

Answer

Drew LeSueur picture Drew LeSueur · Sep 17, 2014

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"});`