DEV Community

Discussion on: HTTPS In Development: A Practical Guide

Collapse
 
zwergius profile image
Christian

I did implement this in CRA yesterday with no need for ejecting.

3 steps:

mkcert localhost

cat ~/.localhost-ssl/localhost-key.pem ~/.localhost-ssl/localhost.pem > {cra-path}/cert/server.pem

and then in package.json

"prestart": "cp -f ./cert/server.pem ./node_modules/webpack-dev-server/ssl || :",

Collapse
 
kmaschta profile image
Kmaschta

Oh nice, thanks!
Can I add this snippet to the blog post and cite you as well?

Collapse
 
zwergius profile image
Christian

Of course! :)

Collapse
 
tcelestino profile image
Tiago Celestino

nice hook.

Collapse
 
justinobney profile image
Justin Obney • Edited

Would you happen to know what this would look like on Windows? I see mkcert works fine on Windows..

UPDATE:

I have this working on Windows using mkcert & customize-cra

config-overrides.js

const fs = require('fs');
const path = require('path');
const {overrideDevServer} = require('customize-cra');

const configureHttps = () => config => {
  return {
    ...config,
    https: {
      key: fs.readFileSync(path.resolve(__dirname, './localhost+2-key.pem')),
      cert: fs.readFileSync(path.resolve(__dirname, './localhost+2.pem')),
    },
  };
};

/* config-overrides.js */
module.exports = {
  devServer: overrideDevServer(
    // dev server plugin
    configureHttps()
  ),
};