I was wondering if anyone knows how to use https on dev for the \'create-react-app\' environment. I can\'t see anything about that in the README or quick googling. I just wa
Set HTTPS=true
before you run the start command.
Documentation
The implementation uses the HTTPS Environment Variable to determine which protocol to use when starting the server.
set HTTPS=true&&react-scripts start
in scripts > start: of package.json as shown below.
"scripts" in package.json:
"scripts": {
"start": "set HTTPS=true&&react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
HTTPS=true && npm start
won't work. Refer it in official doc. Using HTTPS in Development
(Note: the lack of whitespace is intentional.)
HTTPS=true npm start
in the terminal worked for me on Create-React-App
if it's still not working properly because of "your connection is not private" issues (in chrome), this worked for me just fine:
https://github.com/facebook/create-react-app/issues/3441
In short:
You can create a proxy.HTTPS->HTTP
Create a key and cert.
openssl req -nodes -new -x509 -keyout server.key -out server.cert
Create a file named proxyServer.js
var httpProxy = require('http-proxy');
let fs = require('fs');
httpProxy.createServer({
target: {
host: 'localhost',
port: 3000
},
ssl: {
key: fs.readFileSync('server.key', 'utf8'),
cert: fs.readFileSync('server.cert', 'utf8')
}
}).listen(3000);
From the terminal run
node proxyServer.js
"scripts": {
"start": "set HTTPS=true&&set PORT=443&&react-scripts start",
........
}
In case you need to change the port and set it to https.