[Vuejs]-Using SSL in an Express application

-1๐Ÿ‘

โœ…

I got it. If anyone else has this problem in the future:

Changed app.js to this:

const app = require('express')();
const http = require('http').createServer(app);
const https = require('https');
var server = https.createServer({
    key: fs.readFileSync('./key.pem'),
    cert: fs.readFileSync('./cert.pem')
},app);

const io = require("socket.io")(server);
const { ExpressPeerServer } = require('peer');

const customGenerationFunction = () => (Math.random().toString(36) + '0000000000000000000').substr(2, 16);

const peerServer = ExpressPeerServer(server, {
    generateClientId: customGenerationFunction,
    debug: true,
    port: 3000,
    key: 'peerjs',
    ssl:{
        key: fs.readFileSync('./key.pem'),
        cert: fs.readFileSync('./cert.pem')
    },
    allow_discovery: true
});

server.listen(3000, () => {
    console.log("https listening at: 3000");
});

Inside the client:

let Socket = io.connect("https://192.168.178.28:3000"); 
let myPeer = new Peer(undefined, {
  host: "192.168.178.28",
  port: "3000",
  path: "/peerjs",
  key: "peerjs",
});

And finally, vue.config.js:

module.exports = {
    devServer: {
        https: true
    },
};
๐Ÿ‘คramy

Leave a comment