Live data from Hacker News

Developing HTTPS Services in Node with Self-Signed Certificates

mattcbaker.com

11–15 of 15 posts

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

#11

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?

While lots of browsers trust localhost, I've found that there is a significant problem with developing some features. My current project for example uses HttpOnly,Secure cookies, which don't work on localhost.

So either I add an option to disable that (which I don't want to) or I simply reroute my traffic over a domain pointed at localhost I have a cert for.

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

#12
Save a ton of work by placing a http proxy infront of your NodeJS apps, and also let the http proxy serve static content. That way you dont have to implement a http-server+SSL+routing+file-server for each nodejs project. There are a lot of advantages to keeping a program small: For example less bugs, less maintenance, and faster implementation.

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

#13
Me and my engineering team has been working with a combination of Zerotier + Caddy for a while now. We have a development domain and then every engineer has a subdomain, which is just `username.example.com` and `*.username.example.com` that points to their Zerotier address. Since it's all on a Zerotier network, we use DNS-01 validation, which works well.

Each engineer then has caddy running on his development machine with domains such as `server.username.example.com` and `web.username.example.com`.

The useful thing about this is that we're spread out remotely, but can at any point, while pairing or something like that, connect to the services running on each others machines. I've also grown used to simply using my own domain, rather than localhost, when developing, especially since it's served behind HTTPS.

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

#14
post #12

Save a ton of work by placing a http proxy infront of your NodeJS apps, and also let the http proxy serve static content. That way you dont have to implement a http-server+SSL+routing+file-server for each nodejs project. There are a lot of advantages to keeping a program small: For example less bugs, less maintenance, and faster implementation.

I second this. In production I will typically front my Node app with Nginx that takes care of SSL and static file serving. There is also a substantial performance benefit.

Can all be bundled up in a single Docker container for super easy deployment. :)

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

#15
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).

There's various tricks. You can also assign the domain to a static IP long enough to verify your ownership then change it. Using a TXT record is probably easier to automate renewal though.
Post reply on HN