Skip to content

Instantly share code, notes, and snippets.

@anumber8
Forked from jonsamp/localhost-ssl.sh
Created February 8, 2020 05:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anumber8/d852fbb5e9c6389e6d154ac6d6d417e7 to your computer and use it in GitHub Desktop.
Save anumber8/d852fbb5e9c6389e6d154ac6d6d417e7 to your computer and use it in GitHub Desktop.
Create https key and cert on localhost
cd ~/
mkdir .localhost-ssl
sudo openssl genrsa -out ~/.localhost-ssl/localhost.key 2048
sudo openssl req -new -x509 -key ~/.localhost-ssl/localhost.key -out ~/.localhost-ssl/localhost.crt -days 3650 -subj /CN=localhost
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ~/.localhost-ssl/localhost.crt
npm install -g http-server
echo "
function https-server() {
http-server --ssl --cert ~/.localhost-ssl/localhost.crt --key ~/.localhost-ssl/localhost.key
}
" >> ~/.bash_profile
source ~/.bash_profile
echo "You're ready to use https on localhost 💅"
echo "Navigate to a project directory and run:"
echo ""
echo "https-server"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment