Author: Michael Lynch <git@mtlynch.io>
Committer: Michael Lynch <mtlynch@noreply.codeberg.org>
Serve from the handler directly instead of the default ServeMux (#261)
main() wrapped the fully-assembled handler chain (CrossOriginProtection
-> optional ProxyIPHeaders -> LoggingHandler -> router) in a call to
http.Handle("/", h), which registers it on the package-global
http.DefaultServeMux, and then passed nil to http.ListenAndServe so the
server would fall back to that same default mux.
This added an indirection that bought us nothing: h is already a complete
http.Handler, so forwarding all "/" traffic through a ServeMux back into h
is redundant. It also coupled the server to global mutable state. Anything
in the process (including third-party packages) can register routes on
DefaultServeMux, which risks surprising route conflicts or accidentally
exposed endpoints, and it makes the wiring harder to follow and to test.
Drop the http.Handle("/", h) registration and pass h directly to
http.ListenAndServe. Behavior is identical, but the server now serves from
an explicit handler with no reliance on the global default mux.
Reviewed-on: https://codeberg.org/mtlynch/little-moments/pulls/261