Install mkcert; Create local certificate authority; Create certificates for your localhost application.
Mac
Install mkcert using Homebrew
brew install mkcert
brew install nss
Create local certificate authority (CA)
mkcert -install
Create certificates for your localhost application
mkcert localhost localhost 127.0.0.1 ::1
Code language: CSS (css)
Troubleshooting
Problem: Certificate is invalid. When clicking on the insecure warning next to the address bar to inspect the certificate it shows that it was issued by you computer with mkcert.
Solution: You may have missed the step to make mkcert a local CA.