DEV Community

Discussion on: Using Create-React-App with Express

Collapse
 
bkrmsp profile image
Bikram Singh Patel

Hi, can you also help out to setup HTTPS with regards to this arcticle? I have tried to use export HTTPS=true as i am working on MAC. It works fine when i do npm start (i.e. development mode) but not when i started hosting the production build as per the steps you mentioned above.

Collapse
 
lisa profile image
Lisa • Edited

Hi,
Did you get a solution to this?

I tried creating a self-signed certificate by following these steps -

openssl genrsa -out key.pem
openssl req -new -key key.pem -out csr.pem
openssl x509 -req -days 9999 -in csr.pem -signkey key.pem -out cert.pem
rm csr.pem

And to my server.js file, I included the following code -

var express = require("express");
var https = require("https");
var fs = require("fs");
const path = require('path');
var app = express();
const options = {
key: fs.readFileSync('key.pem'),
cert: fs.readFileSync('cert.pem')
};
var server = https.createServer(options, app);
app.use(express.static(__dirname));
app.get('/', function (req, res) {
res.sendFile(path.join(__dirname, 'build'));
});
server.listen(8000);

But this doesn't seem to work for me. When I open https://localhost:3000 it throws a "The site can't provide a secure connection". Can someone point out where I am going wrong?