std/web/static

Standard Library documentation

Static file controller for std/web routes.

Module

Name
std/web/static
Area
Standard Library
Source
modules/std/web/static.zzm

NAME

std/web/static - Static file controller for std/web routes.

SYNOPSIS

  from std/web import Routes;
  from std/io import Path;

  let routes := new Routes();
  routes.get("/img/*path").to(
    controller: "std/web/static#StaticHandler",
    action: "handle",
    root: new Path("public/img"),
  );

DESCRIPTION

This module provides a lazy-loadable std/web controller for serving static files. Configuration is supplied through route defaults, so the same StaticHandler class can be shared by multiple static routes.

The handler rejects absolute request paths, path traversal, and paths escaping the configured root. Directory listings are disabled unless the route enables them.

EXPORTS

StaticHandler

Static methods:

  • handle(req)

    Serves the file indicated by the route capture. The route must supply a root default. Optional defaults are path_param, index_files, directory_indexes, cache_control, and content_types.

COPYRIGHT AND LICENCE

std/web/static is copyright Toby Inkster.

It is free software; you may redistribute it and/or modify it under the terms of either the Artistic License 1.0 or the GNU General Public License version 2.