Add a SSL certificate to your localhost domain during development mode. Local HTTPS on a gatsby site.
In the project root folder in the terminal, run:
openssl req -x509 -newkey rsa:2048 -keyout keytmp.pem -out cert.pem -days 365
First your must create a pass phrase. you will need to remember/note this down as you will need it register your certificate and start your development environment.
Enter PEM pass phrase: ****** Verifying - Enter PEM pass phrase:******
You will be asked a series of questions.
Example Answers:
Run The following command to register the certificate:
openssl rsa -in keytmp.pem -out key.pem
you will be prompted to enter your password you created earlier.
Enter pass phrase for keytmp.pem:
there should be three files created in the root of your project.
in your package.json add the following command to the develop script.
"scripts": {
"develop": "SSL_CRT_FILE=cert.pem&&SSL_KEY_FILE=key.pem gatsby develop --https",
"start": "gatsby develop",
"build": "gatsby build",
"serve": "gatsby serve",
"clean": "gatsby clean"
},
Run the Project
gatsby develop
you will ber promoted to enter the password one time.
That's it your all done. you localhost should now be secure