Live data from Hacker News

Developing HTTPS Services in Node with Self-Signed Certificates

mattcbaker.com

1–10 of 15 posts

Re: Developing HTTPS Services in Node with Self-Signed Certificates

#3

I've never tried to serve HTTPS locally without a proxy (ngrok etc.) or behind a load balancer, because I always end up serving the app with one or the other. And now there's Let's Encrypt. Why would you ever develop with HTTPS locally?

My particular use case might have been kind of weird, but -- I was working on a HTTPS client and I wanted to hit a local HTTPS server for some of the tests in the client.

Re: Developing HTTPS Services in Node with Self-Signed Certificates

#5

I've never tried to serve HTTPS locally without a proxy (ngrok etc.) or behind a load balancer, because I always end up serving the app with one or the other. And now there's Let's Encrypt. Why would you ever develop with HTTPS locally?

> Why would you ever develop with HTTPS locally?

One good reason is to mimic the production environment, as there are an increasing number of browser features that depend on HTTPS (HSTS, cookie secure flags, new html5 APIs like the location api, etc). Though when I do use https locally I also typically use an nginx reverse proxy.

Re: Developing HTTPS Services in Node with Self-Signed Certificates

#6
post #4

If you own a domain, create a A record for local.mydomain.com and point it to 127.0.0.1 and you can generate a valid cert with Let's Encrypt.

In this case you'll need to use the DNS-01 validation method for the domain issuance, not HTTP-01 (because local.mydomain.com won't be able to receive an inbound validation connection from Let's Encrypt).

Re: Developing HTTPS Services in Node with Self-Signed Certificates

#7

I've never tried to serve HTTPS locally without a proxy (ngrok etc.) or behind a load balancer, because I always end up serving the app with one or the other. And now there's Let's Encrypt. Why would you ever develop with HTTPS locally?

HTTP/2 apps need TLS

Re: Developing HTTPS Services in Node with Self-Signed Certificates

#8
post #6
post #4

If you own a domain, create a A record for local.mydomain.com and point it to 127.0.0.1 and you can generate a valid cert with Let's Encrypt.

In this case you'll need to use the DNS-01 validation method for the domain issuance, not HTTP-01 (because local.mydomain.com won't be able to receive an inbound validation connection from Let's Encrypt).

thx for this method. Did not know that there is also another DNS based verification for normal subdomains on letsencrypt.

Re: Developing HTTPS Services in Node with Self-Signed Certificates

#9
You can also front it with Caddy in a single command, no need to generate the self-signed certificate manually and find a place to store it:

$ caddy -host localhost "proxy / localhost:9000" "tls self_signed"

This will serve your Node application (assuming it's on port 9000) at https://localhost:2015/. And you can change the port from the default port with the -port flag.

Re: Developing HTTPS Services in Node with Self-Signed Certificates

#10
post #4

If you own a domain, create a A record for local.mydomain.com and point it to 127.0.0.1 and you can generate a valid cert with Let's Encrypt.

Alternatively, what I do is to sign a wildcard cert for a subdomain plus *.subdomain valid for a couple years and putting the key and cert on my Nextcloud in an encrypted archive file, that way I always have access to a cert that I trust and can easily install on a local computer.
Post reply on HN