Reverse proxy to websocket not working


I’m trying to use a Cloudflare worker as a Reverse proxy for https and websocket requests, but can’t get web socket proxing to work at all. I just get an error saying Fetch API cannot load: wss://<origin web socket server URL>. I’ve tried pointing to a few different websocket servers and always get the same error - suggesting that it’s something within my cloudflare setup that’s wrong. My worker code is based on loads of standard examples out there - I don’t think that’s the problem.

Any ideas what I’m doing wrong?

Thanks in advance.


1 Like

This is the way it works:

// Worker code
export default {
  async fetch(request, env, ctx) {
    return fetch('', request);
// Client code
const ws = new WebSocket('wss://');
// ...

You need to use the https: protocol when overriding the connection URL, and Cloudflare will do the rest under the hood.

Read more here.