Home

Published

- 2 min read

HTTPS in local development

Hero image

Photo by Beth Macdonald on Unsplash


Benefits of encryption for local development

While developing a webpage using HTTP works most of the time, sometimes features are exclusive to HTTPS:

  • Sending CORS request with credentials, requires your page to be in a secure context
  • OAuth / OIDC redirect URIs may not allow insecure HTTP links
  • WebAPIs such as service workers, geolocation, crypto or clipboard access may require a secure context
  • The secure flag on cookies
  • Your linter may flag uses of http:// as insecure

How to enable local HTTPS

First you need a domain that resolves to the loopback address (127.0.0.1 for IPv4 or ::1 for IPv6). The domain name should not be a valid domain on the internet for security, so the .local TLD is usually a good choice. For the domain to be resolve able it needs to be added to the systems host list (/etc/hosts on Linux and macOS or C:\Windows\System32\drivers\etc\hosts on Windows).

Then you need to create a certificate authority, add it to the respective truststore and issue a server certificate from it.

Here all of these details are handled for us:

# Map "dev.local" to the IPv4 loopback address (i.e. localhost)
localca hosts add -4 dev.local
# Add your certificate authority to the system and browser truststores
localca add system nss
# Issue a server certificate for your application
localca issue dev.local

Now all that’s let to do is to make the webserver use the certificate and to restart the browser. A simple way to use the certificate, even when the webserver does not support it is to use a proxy like this:

# Use your server certificate to terminate HTTPS traffic on port 8080
#  and forward it as HTTP traffic to your webserver at port 3000
local-ssl-proxy --key key.pem --cert certificate.pem --source 8080 --target 3000

Further reading

Related Posts

There are no related posts yet. 😢