SSL Socket.IO ERR_CERT_AUTHORITY_INVALID

Viewed 566

i'm trying to connect to my Socket.IO server on Node.JS from a PHP webpage.

I've created a self-signed certificate using the command:

openssl req -newkey rsa:2048 -nodes -keyout self.key -x509 -days 365 -out self.crt

And then, i created a HTTPS server in Node.JS

                  require("dotenv").config();
const express   = require("express");
const consign   = require("consign");
const app       = express();
const http      = require("http").createServer(app);
const https     = require("https");
const fs        = require("fs");
const server = https.createServer({
    key: fs.readFileSync("./config/ssl/self.key", "utf8").toString(),
    cert: fs.readFileSync("./config/ssl/self.crt", "utf8").toString(),
    rejectUnauthorized: false
}, app);
const io        = require("socket.io")(server.listen(4000), {cors: true, origins: ["*"], rejectUnauthorized: false});
const cors      = require("cors");

app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: false }));

io.on("connection", (socket) => {
    let logger = app.app.models.logger;
    logger.log(logger.logType.Debug, "Server", `New socket client connected ${socket.id}`);

    socket.on("disconnect", () => {
        logger.log(logger.logType.Debug, "Server", `Socket client disconnected ${socket.id}`);
    });
});

consign()
        .include("./app/routes")
        .then("./app/models")
        .into(app, io);

module.exports = app;

But, when i try to connect with Socket.IO from my web client, it throws a net::ERR_CERT_AUTHORITY_INVALID error in console

const socket = io("https://localhost:4000", {"reconnectionAttempts": 5, "secure": true});
0 Answers
Related