diff options
| author | Jason Cameron <git@jasoncameron.dev> | 2025-03-29 23:51:13 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-29 23:51:13 -0400 |
| commit | 5a07684f999fc192325567245b5c8a7fd66a27a6 (patch) | |
| tree | 92480b702c03feb491ab6a7c477d3d837d194ca0 /cmd/anubis | |
| parent | 4bc00e5a658b26ed302ba7a697635652f10079a0 (diff) | |
| download | anubis-5a07684f999fc192325567245b5c8a7fd66a27a6.tar.xz anubis-5a07684f999fc192325567245b5c8a7fd66a27a6.zip | |
fix(logs): Correctly format listener address (#162)
* fix: Correctly format listener address (https://github.com/TecharoHQ/anubis/issues/93)
Handle addresses that include a hostname, not just ports. If
the address starts with a colon, assume it's just a port and
prefix it with "http://localhost". Otherwise, prefix the
entire address with "http://". This ensures that the listener
URL is correctly formatted regardless of whether it includes
a hostname or just a port.
Signed-off-by: Jason Cameron <git@jasoncameron.dev>
* chore(docs): add changelog entry
Signed-off-by: Jason Cameron <git@jasoncameron.dev>
---------
Signed-off-by: Jason Cameron <git@jasoncameron.dev>
Diffstat (limited to 'cmd/anubis')
| -rw-r--r-- | cmd/anubis/main.go | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/cmd/anubis/main.go b/cmd/anubis/main.go index 8ab370d..5f858f3 100644 --- a/cmd/anubis/main.go +++ b/cmd/anubis/main.go @@ -17,6 +17,7 @@ import ( "os/signal" "regexp" "strconv" + "strings" "sync" "syscall" "time" @@ -82,7 +83,11 @@ func setupListener(network string, address string) (net.Listener, string) { case "unix": formattedAddress = "unix:" + address case "tcp": - formattedAddress = "http://localhost" + address + if strings.HasPrefix(address, ":") { // assume it's just a port e.g. :4259 + formattedAddress = "http://localhost" + address + } else { + formattedAddress = "http://" + address + } default: formattedAddress = fmt.Sprintf(`(%s) %s`, network, address) } @@ -245,10 +250,10 @@ func main() { h = internal.XForwardedForToXRealIP(h) srv := http.Server{Handler: h} - listener, url := setupListener(*bindNetwork, *bind) + listener, listenerUrl := setupListener(*bindNetwork, *bind) slog.Info( "listening", - "url", url, + "url", listenerUrl, "difficulty", *challengeDifficulty, "serveRobotsTXT", *robotsTxt, "target", *target, |
