crate
weft_server
A tiny, dependency-free static file server for Weft apps.
Built as a static binary it lets a container ship as FROM scratch with only the server and the site — a few megabytes in total. It serves .wasm with the right MIME type, prefers precompressed .gz files, falls back to index.html for client-side routes, exposes /healthz, and refuses path traversal.
Structs
Functions
cache_control
pub fn cache_control(_path: &Path) -> &'static strAsset names aren't content-hashed, so clients always revalidate (a cheap 304 thanks to etag) and new deployments are picked up immediately.
etag
pub fn etag(len: u64, mtime_secs: u64) -> StringA validator built from file size and modification time.
handle
pub fn handle(root: &Path, spa: bool, req: &Request) -> ResponseProduce the response for a request.
health_check
pub fn health_check(port: u16) -> boolGET /healthz on localhost; used as the container health check.
mime_type
pub fn mime_type(path: &Path) -> &'static strThe Content-Type for a file, by its extension (application/octet-stream when unknown).
parse_request
pub fn parse_request(head: &str) -> Result<Request, String>Parse an HTTP/1.x request head.
percent_decode
pub fn percent_decode(s: &str) -> Option<String>Decode %XX escapes; None for malformed escapes or invalid UTF-8.
read_head
pub fn read_head(r: &mut impl Read) -> Result<String>Read a request head (through the blank line) without consuming the body.
redirect_location
pub fn redirect_location(root: &Path, url_path: &str) -> Option<String>/blog → /blog/ (keeping the query) when blog/ is a directory with an index.html, so the page's relative asset paths resolve.
resolve_path
pub fn resolve_path(root: &Path, url_path: &str) -> Option<PathBuf>Map a URL path to an existing file under root, refusing traversal.
rewrites
pub fn rewrites(json: &str) -> Vec<(String, String)>The rewrites in an app's routes.json (written by Weft's prerender): (pattern, destination), where a pattern is a route's (/blog/:slug/, /docs/*path/).
serve
pub fn serve(listener: TcpListener, config: Config)Accept connections forever, one thread per connection.
status_reason
pub fn status_reason(status: u16) -> &'static strThe reason phrase for an HTTP status (404 → Not Found).