“WebSocket connection to ‘wss://mydomain.com:8080/’ failed:” with no extra details

I am trying to host a websocket using node.js and it seems to host fine, but I cannot connect to it externally because I just get the error in the title. The : after failed suggests there should be extra details and similar questions here prove that, but I’m not getting anything after the colon making this very difficult to debug. I have tried in multiple browsers and I get the same error so it’s not my browser causing this. My best guess would be that my cerificates aren’t working, but they’re the same certificates I use for the rest of my websites and they work fine for them so not too sure.

This is my server-side (node.js) code:

const server = require('https').createServer({
    cert: fs.readFileSync('/etc/letsencrypt/live/mydomain.com/fullchain.pem'),
    key: fs.readFileSync('/etc/letsencrypt/live/mydomain.com/privkey.pem')
});

const websocket = new (require('ws').Server)({server});
websocket.on('connection', (client, request) => {
    console.log("New connection from "+request.socket.remoteAddress);
});

And my client-side (Javascript) code is just

new WebSocket("wss://mydomain.com:8080").onmessage = (event) => {
    console.log(event.data);
};

I have tried making my node.js server listen to port 8080 but that made no difference. I have also tried different URLs on the client side (such as without the protocol, without the port, using my ip) but as I would expect, those don’t work either.