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.
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
I also have this problem, my domain registar is Google Domains. No matter how I try, no custom domain, websockets work great, but with the custom domain, websockets don’t work.