fix: proxying to ipv6/localhost backends#49
Merged
peterldowns merged 1 commit intomainfrom Jul 29, 2025
Merged
Conversation
``` python3 -m http.server 8080 --bind 127.0.0.1 python3 -m http.server 8080 --bind localhost python3 -m http.server 8080 --bind ::1 python3 -m http.server 8080 --bind ::1 ``` and check ``` lsof -Pn | grep -E ':8080' localias add frontend.local 8080 localias add frontend.testing 8080 ``` ``` curl 'http://[::]:8080/' curl 'http://[::1]:8080/' curl 'http://127.0.0.1:8080/' curl 'http://localhost:8080/' curl 'https://frontend.local' curl 'https://frontend.testing' ```
0b3e4fa to
d281a8a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #48 by explicitly using
localhost:PORTas the target upstream in eachreverse_proxydirective. Previously, the directive was just:PORT.How does this work?
From testing based on the repro in that linked issue, it seems like the vite server binds to
localhost:5173, which is interpreted as ipv6:For whatever reason, when the caddy upstream is
:5173, this means that requests fail with a 502 upstream error:With this change, the request successfully makes it to the backend server — which then rejects it because the vite devserver requires you to add your aliases to the
allowedHostsconfig. But at this point, localias is working correctly:Caddy docs
The caddy documentation only ever shows binding to
localhost:PORT, see https://caddyserver.com/docs/caddyfile/directives/reverse_proxy#examples. So this change seems to make sense given the upstream docs.Caddy's documentation on Network Addresses mentions that a single port specified as
:PORTis valid, but doesn't really explain the difference betweenlocalhost:PORTand:PORTTesting
frontend.localto the bun/vite dev server as explained above.localhost,127.0.0.1,0.0.0.0, and::, localias allows proxyingfrontend.localto the dev server.Starting with an index.html that just says
ok, and a singe aliasfrontend.local -> 5173: