Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WSS support #155

Open
loretoparisi opened this issue Feb 17, 2022 · 2 comments
Open

WSS support #155

loretoparisi opened this issue Feb 17, 2022 · 2 comments

Comments

@loretoparisi
Copy link

I have a security error in Chrome

app.js:271 Mixed Content: The page at 'https://mywebsite' was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint 'ws://mywebsite/ss/1.0/echo'. This request has been blocked; this endpoint must be available over WSS.

When I switch to wss:// protocol, I have a connection error (I assume):

VM342:1 WebSocket connection to 'wss://mywebsite/ss/1.0/echo' failed: 

the WebSocket object state is like

WebSocket {url: 'wss://mywebsite/ss/1.0/echo', readyState: 0, bufferedAmount: 0, onopen: null, onerror: null, …}
binaryType: "blob"
bufferedAmount: 0
extensions: ""
onclose: null
onerror: null
onmessage: null
onopen: null
protocol: ""
readyState: 3
url: "wss://mywebsite/ss/1.0/echo"

In the server I have

self.ws = expressWs(self.app, self.httpServer.getInstance(), {
    port: 3000,
    perMessageDeflate: false
});

self.app.ws(self._options.wsbaseUrl + '/echo', function(ws, req) {
                ws.on('message', function(msg) {
                    try {
                        const jsonObj = JSON.parse(msg);
                        const jsonString = JSON.stringify(jsonObj);
                        ws.send(jsonString);
                    } catch(error) {
                        self.logger.warn("websocket error:%s", error.toString());
                    }
                });
            });

where

self.app=express()
self.httpServer.getInstance() is the nodejs http server instance

The server is running on port 3000, while a load balancer sends traffic from the 80 over https to the port 3000 over http.

@ghost
Copy link

ghost commented Apr 13, 2022

A website WITH SSL cannot connect to a websocket WITHOUT SSL.

@matthijs166
Copy link

There is an example available here to add HTTPS: https://github.com/HenningM/express-ws/blob/master/examples/https.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants