worktrunk icon indicating copy to clipboard operation
worktrunk copied to clipboard

Docs: .localhost subdomains as alternative to .lvh.me for Caddy routing

Open eduwass opened this issue 8 months ago • 5 comments

Hey! Just discovered the subdomain routing with Caddy pattern in the docs — really cool.

One thing that bugged me though: .lvh.me is a third-party domain that resolves to 127.0.0.1 via public DNS. If that domain ever goes down or changes hands, every dev setup relying on it breaks. It also doesn't work offline, and the example still needs a port (:8080), so it's not fully "clean" either.

.localhost subdomains might be a better default to suggest here:

  • RFC 6761 reserved — browsers/OSes are required to resolve *.localhost to loopback. No external DNS needed.
  • Works offline — no network request leaves your machine
  • Portless with Caddy on 443 — https://feature-branch.myproject.localhost instead of http://feature-branch.myproject.lvh.me:8080
  • Caddy does automatic local TLS for localhost domains, so you get HTTPS for free

The Caddyfile config would be basically the same, just swapping the domain pattern. Something like:

*.myproject.localhost {
  tls internal
  reverse_proxy {re.match.1}:{re.match.1 | hash_port}
}

(rough sketch, would need to adapt to the Caddy API approach in the current docs)

Would you be open to adding this as an alternative pattern in the tips page? Happy to PR if useful.

eduwass avatar Mar 07 '26 19:03 eduwass

Thanks for the suggestion! I searched the codebase and the existing Caddy subdomain routing section only covers the .lvh.me approach — there's no mention of .localhost as an alternative.

The points about offline support, no external DNS dependency, and automatic local TLS via Caddy are compelling tradeoffs to document alongside the current pattern.

I'll leave it for a maintainer to evaluate and prioritize. A PR adding this as an alternative pattern in the tips page would be welcome if the maintainer agrees.

worktrunk-bot avatar Mar 07 '26 19:03 worktrunk-bot

thanks for the suggestion!

is there any downside of the .localhost approach? I did the .lvh.me approach because I thought that was standard, but I have no personal view beyond "let's do what's standard", so happy to change it if that dominates.

my goal is for the docs to be simple and secular (i.e. this isn't the place they should make divergent claims). I would prefer to only have one example, but could add "(or https://feature-branch.myproject.localhost if preferred)" if there are legit reasons to have both?

max-sixty avatar Mar 07 '26 20:03 max-sixty

@max-sixty

The main difference is that .lvh.me is just a regular domain owned by someone who configured a wildcard DNS record pointing to 127.0.0.1. It works well in practice, but it still depends on an external domain and DNS resolution. The owner could stop renewing the domain or point it to a different IP in the future. Also means that if you are offline you can't access your domain.

.localhost, on the other hand, is reserved by RFC 6761 and operating systems/browsers are required to resolve *.localhost to loopback. So it doesn’t rely on any third-party domain and works fully offline.

So the main benefit is that it’s a standards-based approach that doesn’t depend on a public DNS domain. Because of that it feels like a safer default for documentation.

tldr;

  • downside: can't think of any
  • pros: a more standard/safe solution

this approach is being pushed by other projects like https://github.com/vercel-labs/portless

eduwass avatar Mar 07 '26 21:03 eduwass

thanks @eduwass ! let's do it, then

@worktrunk-bot could you draft this change + research if there are any downsides / unsupported browsers etc?

max-sixty avatar Mar 07 '26 21:03 max-sixty

Drafted the change in #1343 — switches all .lvh.me references to .localhost across docs, CLI help text, and tests.

Here's what I found on compatibility:

Browser support for *.localhost → loopback resolution:

Browser Since Notes
Chrome 118 (Oct 2023) Resolves *.localhost to loopback per spec
Firefox 84 (Dec 2020) Earliest mainstream adopter
Safari 16 (Sep 2022) Includes iOS Safari
Edge 118 (Oct 2023) Chromium-based, same as Chrome

All current browser versions support it. The oldest browser to add support (Firefox 84) is over 5 years old at this point.

OS-level resolution:

  • macOS: Resolves *.localhost natively
  • Linux (systemd-resolved): Handles *.localhost via NSS — covers most modern distros
  • Linux (without systemd): May need dnsmasq or an /etc/hosts entry, though most dev-oriented setups have systemd-resolved
  • Windows: Resolves localhost but *.localhost subdomain support varies — WSL environments (common for dev) work fine

Downsides I could find:

  • Older corporate proxy setups that intercept DNS might not handle *.localhost correctly (same issue exists with .lvh.me though, since proxies may block external DNS too)
  • Very old browsers (pre-2022) won't resolve subdomains — but these are well past EOL

Net: .localhost is the strictly better default for documentation. It's standards-based (RFC 6761), works offline, has no third-party dependency, and is supported by all browsers anyone would reasonably be developing with today.

worktrunk-bot avatar Mar 07 '26 22:03 worktrunk-bot