Serve localhost with HTTPS using a single command

Serving localhost with HTTPS is a common need while developping a Web application that needs resources from another host, but it’s cumbersome because of the CORS issues and the need to install self-signed certificates or disable security features in the browser.

Thankfully, Pierre-Mikael Legris, a developer in Switzerland, recently released Backloop.dev: the DNS entries for *.backlog.dev all point to 127.0.0.1 (localhost), and the homepage lists the certificates to download and use locally. To automate this, he made the homonyme NPM package.

Here is how to use it:

  1. Install the package: npm install backloop.dev -g
  2. Run backloop.dev-proxy localhost:<your port>

Now open https://whatever.backloop.dev:4443/ (you can replace whatever by… whatever, like my-app).
That’s all.

This is not one of these tunnel apps that expose your local app on the outside; anyone accessing this URL would see their own local app (if any). Under the hood, the CLI tool downloads the latest certificates for *.backloop.dev, and proxies your app on 127.0.0.1:4443 with them. Since *.backloop.dev points to 127.0.0.1, you can use whatever subdomain and see your app. For additional security, you can hardcode this by adding this line in your /etc/hosts:

127.0.0.1 whatever.backloop.dev

This ensure that even if Backloop.dev is compromised, this domain still points to localhost.

If you have a Node app, you can install this tool as a script:

npm install backloop.dev --save-dev

Then edit your package.json to add this:

"scripts": {
  "local-https": "backloop.dev-proxy localhost:5173"
}

Replace 5173 by the port your app listens on. Now you can run npm run local-https to proxy your app with HTTPS.