e721196d

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

Suite timing

Time to Start Worker time Duration Time to finish
Config 2s 53s 53s 55s
Eval 53s 2m09s 2m09s 3m02s
Build 1m18s 11m32s 4m40s 5m58s
Deploy 6m11s 2m15s 2m16s 8m28s
Suite 2s 16m50s 8m25s 8m28s

Timeline

0s1m2m3m4m5m7m8m