I followed this post and I created this below:
const express = require('express');
const https = require('https');
const WebSocket = require('ws');
const fs = require('fs');
var privateKey = fs.readFileSync('key.pem', 'utf8');
var certificate = fs.readFileSync('cert.pem', 'utf8');
var credentials = {key: privateKey, cert: certificate};
var app = express();
var httpsServer = https.createServer(credentials, app);
httpsServer.listen(3000);
var WebSocketServer = require('ws').Server;
var wss = new WebSocketServer({
server: httpsServer
});
wss.on('connection', function connection(ws) {
ws.on('message', function incoming(message) {
console.log('received: %s', message);
});
ws.send('something');
});
Running this seems fine on the surface, but then when I try to connect to said websocket on the same ec2 instance with ws = new WebSocket('wss://(the private or public Ip, or the domain for my website, I tried all of them):3000';
and I get the error: WebSocket connection to 'wss://stuff' failed:
Are there additional logs I could look at that might reveal the problem, maybe an additional step I need because of how I'm trying to set this up on an ec2, or is there just something plain wrong with what I did here? Thanks!