Skip to content

Route local dev hostnames that resolve to loopback to the host machine - #1

Open
ygerasimov wants to merge 1 commit into
mainfrom
fix/local-capture-loopback-dns-hostnames
Open

Route local dev hostnames that resolve to loopback to the host machine#1
ygerasimov wants to merge 1 commit into
mainfrom
fix/local-capture-loopback-dns-hostnames

Conversation

@ygerasimov

Copy link
Copy Markdown

Summary

  • run-worker.mjs's containerReachableUrl() only rewrote literal localhost/127.0.0.1-style hostnames to host.docker.internal. Local dev tooling (ddev's *.ddev.site, Lando's *.lndo.site, *.test/*.localhost setups) serves custom hostnames whose public DNS also resolves to a loopback address — but the screenshot-worker container can't reach the host through those, since 127.0.0.1 inside the container is the container itself. Captures against these URLs silently failed with "this site can't be reached".
  • The function now does a DNS lookup for any hostname that isn't one of the known local literals, and if it resolves to a loopback address, routes it to the host via an extra --add-host <hostname>:host-gateway on the container instead of rewriting the URL — keeping the original hostname intact so TLS SNI and Host-based vhost routing (e.g. ddev's router) still work correctly.
  • Bumped plugin version 2.2.0 → 2.2.1 and updated upload-screenshot/SKILL.md to describe the new behavior.

Test plan

  • node --check passes on the modified script
  • Unit-verified containerReachableUrl() against localhost, 127.0.0.1, a ddev hostname, and a normal remote hostname — literal-local rewrite behavior unchanged, ddev hostname now correctly routed via --add-host, remote hostname unaffected
  • End-to-end: captured a running ddev site (https://d11.ddev.site:33001) through the worker container using the patched script — screenshots succeeded (previously failed with "site can't be reached" using the unpatched script against the same URL)

🤖 Generated with Claude Code

run-worker.mjs only rewrote literal localhost/127.0.0.1-style hostnames to
host.docker.internal. Local dev tooling (ddev's *.ddev.site, Lando's
*.lndo.site, *.test/*.localhost setups) serves custom hostnames whose public
DNS also resolves to a loopback address, but the screenshot-worker container
can't reach the host through those - 127.0.0.1 inside the container is the
container itself, so captures silently failed with "site can't be reached".

containerReachableUrl() now does a DNS lookup for any hostname that isn't one
of the known local literals, and if it resolves to a loopback address, routes
it to the host via an extra `--add-host <hostname>:host-gateway` instead of
rewriting the URL - keeping the original hostname intact so TLS SNI and
Host-based vhost routing (as ddev's router relies on) still work.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant