Using HTTPS for local development
Generate certificates
brew install mkcert# Create and install a local trusted CA
mkcert -install
# Generate certificates
mkcert 127.0.0.1Start server with certificates
Use http-server as an example:
npx http-server --tls \
--cert 127.0.0.1.pem \
--key 127.0.0.1-key.pem \
-oBy using -o, http-server will open https://127.0.0.1:8080 in browser automatically.
Advanced
Local DNS mapping
Add the following line into /etc/hosts
Reverse proxy
Let's say there's a service running at
http://localhost:3000, we don't have control for its tls config. So we are going to start another server to reverse proxy the previous one.
Here we use mitmproxy to reverse proxy
Run reverse proxy at 443 port
https://example.dev is working now
Last updated