The external HTTP/S Server example provided in the README doesn't appear to work.
server.js5443node server.jsI expect to see something sent to the browser.
The browser first complains about the self-signed certificate as expected. After selecting to proceed, the browser loading icon just spins. There is nothing sent to the browser. Eventually it times out.

Where is the client? I see no client connecting to the server.
Ah sorry.. The client is the browser with some JavaScript to connect to wss://localhost:5444 along with onopen and onmessage handlers
Yes but I see no request upgrade request in your network tab. Where is the client created and the handshake request initiated?
I鈥檓 guessing that is my problem? Can you point me in the right direction to do what you鈥檙e talking about?
Make your server return something like this to the browser:
const data = `<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<script>
(function () {
var ws = new WebSocket('wss://localhost:8080');
ws.onopen = function () {
console.log('open');
};
})();
</script>
</body>
</html>`;
server.on('request', (req, res) => {
res.setHeader('Content-Type', 'text/html');
res.end(data);
});
Ok that is excellent, progress, YAY.. Last piece of the puzzle i need to request help for is in a HTTP POST from the client, i handle that on the server inside server.on('request'), but how do i send back to the client?
server.on('request', (req, res) => {
const { statusCode, statusMessage, headers, method, url, path } = req
console.log(statusCode, statusMessage, headers, method,url,path )
if (url === '/') {
res.setHeader('Content-Type', 'text/html');
res.end(fs.readFileSync('index.html'))
}
if (req.url === '/send') {
console.log(req.url)
let body = [];
req.on('error', (err) => {
console.error(err)
})
req.on('data', (chunk) => {
body.push(chunk);
})
req.on('end', () => {
body = Buffer.concat(body).toString()
ws.send('something else') // <-- this is not right
res.on('error', (err) => {
console.error(err)
})
})
res.end()
return
}
})
Ok I think you can ignore my previous post.. I believe i should be sending and receiving data over the websocket, not via http get and post.. is that correct?
It depends on you but yes, you can't send a response for a pending request on the websocket.
Closing this as it's not an issue in ws, please use another channel for general support questions.
Most helpful comment
Make your server return something like this to the browser: