0

I am using node js express with socket.io and apache for my reverse proxy. Below is my reverse proxy configuration.

ProxyPass /chatApp http://localhost:3000/
ProxyPassReverse /chatApp http://localhost:3000/

So, my application will be accessed by https://server.com/chatApp. Below is how socket is defined in my html.

var socket = io("https://server.com/chatApp")

The browser throws the following error.

GET https://server.com/socket.io/?EIO=3&transport=polling&t=M9zVwUq 404 (Not Found)

But, when I hit the below URL in the browser, I am getting some results.

https://server.com/chatApp/socket.io/?EIO=3&transport=polling&t=M9zVwUq

Even though, I have mentioned /chatApp in my html (while defining socket variable), my application is not calling server.com/chatApp/socket.io/?EIO..... It's skipping chatApp in the URL, and just calling server.com/socket.io/?EIO...

I've tried the solution to this post. No luck.

Hari Ram
  • 317
  • 4
  • 21

1 Answers1

4

In socket.io's io() interface, the path you pass there is not used as the path on the URL. It's used as the namespace you want to connect to. If you want to specific a custom path, you need to use a separate argument:

var socket = io("https://server.com", {path: "/chatApp/socket.io"});

If this still isn't giving you exactly what you want, then examine what URL socket.io is using (look in the network tab of the Chrome debugger to see it) and then adjust the path argument accordingly.

Here's the socket.io documentation reference for the path option: https://github.com/socketio/socket.io-client/blob/master/docs/API.md#with-custom-path.

Note the /socket.io part of the path is required so the server can properly identify socket.io requests.

jfriend00
  • 683,504
  • 96
  • 985
  • 979