cloudflare / cloudflared

Cloudflare Tunnel client (formerly Argo Tunnel)
https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/install-and-setup/tunnel-guide
Apache License 2.0
9.4k stars 837 forks source link

🐛 Websocket timeout when upgrading insequre ws request to use wss #1306

Open nooisy opened 3 months ago

nooisy commented 3 months ago

Describe the bug I'm trying to remotely access a Bela device . A webpage can be accessed on port 80 and certain parts of the webpage need a websocket connection (:5555) page to render. Locally the whole page works but remotely the websocket part fails to load. Firefox console gives me:

My config.yaml looks like this:

url: http://localhost:80
tunnel:
credentials-file:
ingress:
  - hostname: bela.domain.app
    service: http://localhost:80
  - hostname: bela.domain.app
    service: ws://localhost:5555
  - service: http_status:404
nooisy commented 3 months ago

Ok, after some digging I changed a line in a file called BelaWebSocket.js to use wss, now it looks like this: this.url = "wss://" + this.ip + ":"+this.port+"/"+this.address;

The firefox dev console however now gives me:

Firefox can’t establish a connection to the server at wss://bela.domain.net:5555/gui_control. 
Error: undefined
error { target: WebSocket, isTrusted: true, srcElement: WebSocket, currentTarget: WebSocket, eventPhase: 2, bubbles: false, cancelable: false, returnValue: true, defaultPrevented: false, composed: false, … }
Socket closed
Reconnecting(1)... 
Object { port: 5555, address: "gui_control", ip: "bela.domain.net", ws: WebSocket, connectInterval: 1500, url: "wss://bela.domain.net:5555/gui_control", projectName: null, sliders: [], selectors: [], gui: null, … }
Retrying connection in 1500 ms

It says closed but

netstat -tuln | grep 5555
tcp        0      0 0.0.0.0:5555            0.0.0.0:*               LISTEN    

I have changed the ingress rule to use wss to but to no avail unfortunately

codenoid commented 3 months ago

is there any kind of base url config on your webapp? because it's supposed to only access bela.domain.net instead of bela.domain.net with port 5555

nooisy commented 2 months ago

Honestly, I still have no clue how to make it work. If anyone ever finds out, love to hear from you :) Also posted this issue on the Bela forum.