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
127.0.0.1 example.devReverse 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
brew install mitmproxymkcert -cert-file ./example.dev.pem \
-key-file ./example.dev.pem \
example.devRun reverse proxy at 443 port
mitmproxy --listen-port 443 \
--mode reverse:http://localhost:3000 \
--certs example.dev.pemhttps://example.dev is working now
Last updated