sigildocs

(sigil cli serve)

(sigil cli serve) - Static file server for local web-app testing.

Backs the sigil serve subcommand. It serves a directory of static files over HTTP for local testing of a Sigil browser app: point it at the web build output (build/web/ by default) and open the printed URL.

Built on (sigil http) (server + mime) rather than a hand-rolled socket loop, so MIME types (notably .wasm -> application/wasm), Content-Length, and binary-safe transfer come from the shared library. Files are read as bytevectors so binary assets (the .wasm) are served byte-accurately.

This module is loaded lazily by the CLI (it pulls in (sigil http), which is not present in the bootstrap CLI). See serve-handler in (sigil cli).

Exports

Strip every leading "/" so a request path is always treated as relative to the served root (an absolute second arg would otherwise make path-join ignore the root entirely).

resolve-fileprocedure

Resolve a request path to a readable file under root, or #f. Directories resolve to their index.html. The normalized target must stay within root (path-normalize collapses ".." so traversal is rejected).

file-responseprocedure

Build the response for a resolved file. Compression is delegated to the shared (sigil http) helper http-response-gzip, which negotiates against the request's Accept-Encoding and only compresses worthwhile types.

Build a handler that serves static files from root.

Verify we can actually bind host:port, exception-free.

http-server-start does raise when tcp-listen fails, but that raise is not survivable in a release binary: sigil serve on an occupied port printed "serving <dir>", served nothing, and exited 0. A guard that relies on raise propagating is worthless in exactly the binary where propagation is broken, so this is a plain conditional plus a plain exit — the same reasoning as the fail-loud gate in build-cmds.sgl.

The probe socket is closed immediately and http-serve binds for real a moment later. That leaves a small window in which another process could take the port, which is fine: the point is to convert the overwhelmingly common case (something is already listening) from a silent success into a loud failure, not to provide an atomicity guarantee the OS does not offer here.

serve-mainprocedure

Serve root over HTTP on host:port. Blocks until interrupted.

Order matters: every claim printed here is printed only AFTER the thing it claims has been verified. root is echoed as an absolute path because it is resolved relative to the current directory, and a stale cwd silently serving the wrong tree (404ing everything) was its own papercut.