-
-
Notifications
You must be signed in to change notification settings - Fork 27k
HTTPS in Development #6126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Have you tried it in all browsers lately? I like devcert-san but the last time I tried it (over a year ago) the Firefox and Safari experience was still less than ideal. |
@jimthedev I try my best to test things on various browsers throughout the week like a good dev (both CRA and Gatsby)! Personally speaking, I haven't had any issues with the Gatsby SSL -- and the one that I did have I finally drilled down on this morning. For Firefox it actually requests you trust the assigning Certificate Authority which may have been a solution to any problems it was having their. For Safari though I haven't noticed any fuss. Maybe I'm just lucky though 🤓 |
Just to follow up, I also found this but haven't worked with it (yet). |
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs. |
idk, is this stale? |
It would at least be good to allow specifying a path to load the certificates from. That way you can use |
The simple steps below worked for me:
Similar discussions: Original solution by @Zwerge here: HTTPS In Development: A Practical Guide |
For those who searching for command line example, use the following: (thanks @rlueder)
Otherwise, Chrome may block localhost https from loading. (at least for me recently) Hopefully this PR will solve it completely later - #5845 |
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs. |
idk, is this stale ... again? |
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs. |
Nope, still waiting on the PR to be merged |
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs. |
Since you enable HTTPS by setting The environment variable names can be different if there is something more conventional that would "just work" in some environments. I'd be happy to put in a PR if there is any interest. react-scripts/config/webpackDevServer.config.js
|
@JamesMaroney a PR implementing this feature has been open for a long time now: #5845 It seems that this feature is of no interest to Facebook so they're ignoring it. |
@albertorestifo I've edited the original issue with the mention of the PR just so it's not lost in the noise. :) |
For Ubuntu Debian/Bionic export VER="v1.3.0" sudo chmod 777 mkcert It's generate private key and certificate add both into single file, create a single file httpscert.pem same place as package.json exist and add the both key & certificate into it. For Linux For Windows npm start It's will works fine. |
There is another way to setup HTTPS in development. You can generate cert with const fs = require('fs');
const path = require('path');
const proxy = require('http-proxy-middleware');
const makeCert = () => {
const devServerCertPath = path.resolve(
path.join(require.resolve('webpack-dev-server'), '../../'),
'ssl/server.pem'
);
if (fs.existsSync(devServerCertPath)) {
console.log('webpack-dev-server cert already exists, skipping');
return;
}
const keyPath = path.resolve(path.join(__dirname, '..'), process.env.SSL_KEY_FILE);
if (!fs.existsSync(keyPath)) {
console.error(`Cert key is missing at ${keyPath}`);
process.exit(-1);
}
const certPath = path.resolve(path.join(__dirname, '..'), process.env.SSL_CRT_FILE);
if (!fs.existsSync(keyPath)) {
console.error(`Cert is missing at ${certPath}`);
process.exit(-1);
}
const key = fs.readFileSync(keyPath, 'utf8');
const cert = fs.readFileSync(certPath, 'utf8');
const fullCert = key + cert;
fs.writeFileSync(devServerCertPath, fullCert);
console.log(`Cert is writtent to ${devServerCertPath}`);
};
module.exports = (app) => {
if (process.env.HTTPS === 'true') {
makeCert();
}
}; |
Coming here with the same output as the one presented by @noetix |
I' m having the same issue. I have it running on a docker container but accessing through network. maybe that's related? as subject and issuer are localhost, but I'm accessing through a completely different network IP |
@noetix @Lukortech @Fedexyz
|
Can confirm updating react-scripts to latest unblocks what I reported. |
I had to update |
@iansu I believe this has already landed using https://create-react-app.dev/docs/using-https-in-development/ |
I think the docs still need a guide or at least a link about how to create your own certificate. |
@rlueder step 2 is unclear to me - so I should have two private keys in one file? |
this didnt work for me: PORT=3015 HTTPS='true' \
SSL_CRT_FILE='certs/localhost/server.crt' \
SSL_KEY_FILE='certs/localhost/server.key' \
react-scripts start but this did work eventually: cp -f ./certs/localhost/server.pem ./node_modules/webpack-dev-server/ssl/server.pem
PORT=3015 HTTPS='true' react-scripts start I copied my server.crt and server.key into the new server.pem file. the server.crt content was first, the server.key content was second, so basically two private keys in one file (server.pem). This seems so fucking ridiculous, why the first one didn't work :( |
For anyone else still experiencing this issue, the following worked for me: "scripts": {
"start": "HTTPS=true react-scripts start",
"prestart": "cp -f ./.cert/key.pem ./node_modules/webpack-dev-server/ssl/server.pem && cat ./.cert/cert.pem >> ./node_modules/webpack-dev-server/ssl/server.pem",
},
|
You can specify the certificates location with environment variables or in a .ENV file and won't need the |
@wozzo Does this work with webpack-dev-server < v3.9? Because there's a bug and the |
It needs react-scripts 3.4.2+ |
…facebook/create-react-app#6126. Also need to add logout.
A workaround has been commented below, see: #6126 (comment)
Right now there's just the general acceptance that the SSL Certificate will cause some friction.
React's website (and the development world really) has been gifted with Gatsby, and I think they got it right.
When you run a gatsby website in development mode with the
--https
flag, it will leverage the package devcert-san. It's (near) frictionless, handles trusting the CA and gets you a proper lock on the browser bar.I don't think it's really a high priority but wanted to bring it up.
EDIT:
The text was updated successfully, but these errors were encountered: