serve#
Serve a static site directory locally for preview/testing (e.g. a GitHub Pages build output).
Functions#
- serve_static_site dir [port=8000]
- Purpose: Start a static HTTP server rooted at
dirfor local preview. - Behavior: Auto-selects the first free TCP port in the window
port..port+19(up to 20 ports). Preferspython3 -m http.server, falls back topython(itshttp.serveron Python 3 orSimpleHTTPServeron Python 2), thennpx http-server. Prints the URL and blocks (serves until Ctrl-C). - Returns:
2ifdiris missing/not a directory orportis not a valid number (1-65535);3if no supported server runtime (python3/python/npx) is found;4if no free port is found in the probe window; otherwise runs until interrupted.
CLI wrapper#
bin/serve-pages <dir> [port]- sources this module and callsserve_static_site "$@".
Dependencies#
python3(preferred), orpython(http.serveron Python 3 /SimpleHTTPServeron Python 2), ornpx(http-server) - first one found is used./dev/tcp(bash built-in) for the free-port probe.