The Websocket server seems unable to properly digest a HTTP(S) server when using NodeJS class schematics. The same examples with functions in the public namespace work:
But once in the new class syntax functionality breaks:
HTTP https://pastebin.com/raw/8AuyrETb
HTTPS https://pastebin.com/JQSVRBBp
version:
Node.js version(s): v6.11.4, likely more
OS version(s): Windows 10, Linux Mint 18.2
[#] Initializing server on port 8080...
[#] Webserver started!
[#] Websocket service started!
[#] Initializing services on port 8080...
/home/test/Documents/Projects/x/prototypes/node_modules/ws/lib/WebSocketServer.js:63
throw new TypeError('missing or invalid options');
^
TypeError: missing or invalid options
at WebSocketServer (/home/test/Documents/Projects/x/prototypes/node_modules/ws/lib/WebSocketServer.js:63:13)
at Server.initWebsocketServer (/home/test/Documents/Projects/x/prototypes/services.js:21:26)
at new Server (/home/test/Documents/Projects/x/prototypes/services.js:9:14)
at Object.<anonymous> (/home/test/Documents/Projects/x/prototypes/services.js:25:16)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
You should pass an options object to the WebSocketServer constructor:
const wss = new WebSocket.Server({ server: httpServer });
Your first example works because your HttpsServer instance has a server property but technically it is still not correct.
Most helpful comment
You should pass an options object to the
WebSocketServerconstructor:Your first example works because your
HttpsServerinstance has aserverproperty but technically it is still not correct.