Can;t get Socket.io to work with Caddy V2

1. The problem I’m having:

I’ve got a frontend and backend where the backend is running a socket.io server on port 4000. The frontend is trying to connect to that socket.io server like so:

const socket = io.connect("https://mydomain/webrtc");

The browser console output seems to be saying ERR_NAME_NOT_RESOLVED while trying to connect to this:

https://mydomain/socket.io/?EIO=4&transport=polling&t=PCKBCy7

Problem is, I want it to connect to /webrtc/socket.io/* and not directly to the domain.

My caddy file looks like this:


	handle /webrtc {
		reverse_proxy localhost:4000
	}

I’ve also tried the recommended advice here:

But that gives me the same error in the browser.

Am I missing something? It seems like the frontend is ignoring the /webrtc prefix which I’d be ok with if I can get caddy to handle /socket.io directly.

That means your browser can’t resolve mydomain to an IP address using DNS. You need to use a real domain.

Not to mention, the request made has the path /socket.io/, not /webrtc. Your handle does not match the correct path.

Socket.IO is websockets, not webrtc. Wrong technology.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.