I'm trying to connect my socket.io nodejs server to my Angular 9 client. It worked as I was developing my webapp using http, but for production I need to change the connection to be HTTPS, but I'm getting this error:
WebSocket connection to 'wss://localhost:4444/socket.io/?EIO=3&transport=websocket' failed: Error in connection establishment: net::ERR_CERT_INVALID
This is how I initialise the nodeJS server:
var fs = require('fs');
var https = require('https');
var express = require('express');
var app = express();
var options = {
key: fs.readFileSync('./src/file.pem'),
cert: fs.readFileSync('./src/file.crt')
};
var httpsServer = https.createServer(options, app);
var io = require('socket.io')(https);
io.on("connection", socket => {
...
});
and I'm connecting my Angular webapp like this:
const config: SocketIoConfig = { url: 'https://localhost:4444', options: { transports: ['websocket'], rejectUnauthorized: false } };
...
imports: [
SocketIoModule.forRoot(config),
...
]
I know the rejectUnauthorized will allow MITM attacks but i just can't figure out whats not working.
Any help would be very appreciated!