WebSockets do not work on Custom domain?

I am currently adding websockets to my server but came to a very strange discovery, The websockets Immediately close before connecting when i use my Custom domain, the project.glitch.me domain however works perfectly fine. I am using the Express-ws package (I have very Complex routers). Is there some special handeling or forwarding I need to do to get this working?

DNS hosting is Namecheap if it’s something i have to do with the dns

Could you share a project link, expected behavior, some logs and maybe some code? If it’s “very complex rout[ing]” it might take a while for someone else to understand it, and it’ll be faster if you show them code where you suspect the error is.

I’ve worked with a little websockets with nodejs previously.

When s2sl was being worked on, we used os.js which used websockets, I’ll see if I can find out a reason why websockets didn’t work


looks like there hasn’t been a solution for it yet, if you use cloudflare you might have issues with websockets
I’m actually confused cloudflare says it should work


maybe the fly.io proxy doesn’t work with websockets?
4 Likes

router.ws is defined elsewhere using express-ws package

const api = require("express").Router();
    api.ws("/Echo", (ws,req)=>{
      console.log("Connection Opening")
      ws.on("message", function (msg){
        console.log(msg)
        ws.send(msg)
      })
      ws.on('close', () => {
            console.log('WebSocket was closed')
        })
    })
module properly exported later

Test Cases with Logging:

WS: connect ws://MyDomain/path/Echo
Connection Opening
WebSocket was Closed
WS: Test - timeout
WS: Test - timeout
WS: It Works - timeout


WS: connect ws://project.glitch.me/path/Echo
Connection Opening
WS: Test
Test
WS: Test
Test
WS: It Works
It Works

Also the DNS host is Namecheap