I have an Electron app with a node web server where our website can POST and GET information from the Electron app. The issue is that the website is SSL enabled (HTTPS) but the Electron app is HTTP. Of course, this causes a mixed content exception.
Current Electron Web Server example
http.createServer(function(req,res){
var pathname=url.parse(req.url).pathname;
var query = url.parse(req.url).query;
//enable CORS
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Request-Method', '*');
res.setHeader('Access-Control-Allow-Headers', '*');
switch(pathname){
case '/post':
createPrintWindow(query);
res.end('{"status":"200 OK"}');
break;
default:
res.end('{"status":"running","currentVersion":"'+app.getVersion()+'","isUpdateAvailable":"false"}');
break;
}
}).listen(3000);
I see that I can enable SSL pretty easily:
var express = require('express');
var https = require('https');
var http = require('http');
var fs = require('fs');
// This line is from the Node.js HTTPS documentation.
var options = {
key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
cert: fs.readFileSync('test/fixtures/keys/agent2-cert.cert')
};
// Create a service (the app object is just a callback).
var app = express();
// Create an HTTP service.
http.createServer(app).listen(80);
// Create an HTTPS service identical to the HTTP service.
https.createServer(options, app).listen(443);
How to create an HTTPS server in Node.js?
My problem is, I'm not sure how to generate the actual certificates for both win32 and 64x during the installation process (I'm using electron-buider). I know I can do openSSL, but most machines with not have openSSL installed.
I've even found this, but I don't see any documentation or usage examples of it. https://github.com/electron-userland/electron-builder/blob/master/packages/electron-builder/src/cli/create-self-signed-cert.ts