Skip to content

Instantly share code, notes, and snippets.

@syst3mw0rm
Forked from jonsamp/localhost-ssl.sh
Created July 30, 2019 22:14
Show Gist options
  • Select an option

  • Save syst3mw0rm/88155d1d80bc543a7ffb54c4ceb20876 to your computer and use it in GitHub Desktop.

Select an option

Save syst3mw0rm/88155d1d80bc543a7ffb54c4ceb20876 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 -p 443 -P http://localhost:3000/
}
" >> ~/.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"
@ParashuramJoshi23
Copy link
Copy Markdown

replace ~/.bash_profile with ~/.zshrc as zsh is the default shell

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment