Module middleware/static

Middleware for serving static resources.

This installs a static() method in the application that accepts the following arguments:

  • `base`: the base resource directory (required)
  • `index`: the name of a file to serve if the path matches a directory (e.g. "index.html")
  • `baseURI`: a common prefix for a resource URI (e.g. "/static")
  • `options`: an object with fine-grained configuration options
    • `servePrecompressed`: if true (default), static resources with a pre-compressed gzip equivalent will be served instead of the original file.
    • `maxAge`: set the `Cache-Control` header in seconds, default is 0.
    • `lastModified`: if true (default), set the `Last-Modified` header to the modification date of the resource.
    • `setHeaders`: allows a user to specify a function which returns additional headers to be set for a given path. The given function produces an object containing the header names as keys and takes the path as argument. User-provided headers take precedence over all other headers.
    • `dotfiles`: determines how should files starting with a dot character be treated. `allow` (default) serves dotfiles, `deny` respond with status 403, `ignore` respond with status 404.

You can call static() multiple times to register multiple resources to be served.


middleware (next, app)

Middleware for serving static resources.


Function next

the wrapped middleware chain

Object app

the Stick Application object



a JSGI middleware function