ctrlplusb / react-universally

A starter kit for universal react applications.
MIT License
1.69k stars 243 forks source link

Enabling SSL? #478

Closed eurobob closed 7 years ago

eurobob commented 7 years ago

I've been trying to create a https listener instead of http, but I can't make it work :/

eurobob commented 7 years ago

So i figured it out, I had to create a certificate first. Hopefully this will help others.

Ended up down this path due to service workers requiring a https connection and I wanted to test. Would still be interested in knowing if there was a simpler way that I overlooked :)


const cert = fs.readFileSync('cert.pem');
const options = {
  key: key,
  cert: cert,
  passphrase: 'XXXXXXXX', // optional if you protected the cert with a passphrase
};
const https = require('https').createServer(options, app);

// Create an http listener for our express app.
const listener = https.listen(config.port, config.host, () =>
  console.log(`Server listening on port ${config.port}`),
);