Documentation Index
Fetch the complete documentation index at: https://mintlify.com/binary-person/rammerhead/llms.txt
Use this file to discover all available pages before exploring further.
addStaticFilesToProxy walks a directory recursively and registers each file as a GET route on the proxy. An index.html at any directory level is additionally mounted at the directory path itself (e.g. /index.html is also served at /). MIME types are detected automatically from file extensions.
This is how Rammerhead’s default public/ directory is served. You can call it with your own directory to replace or supplement the built-in UI.
Signature
A
RammerheadProxy (or any testcafe-hammerhead Proxy) instance. Files are registered by calling proxy.GET(route, staticContent).Absolute path to the directory whose contents should be served. Must be a directory — a
TypeError is thrown otherwise.The URL prefix under which files are mounted. Defaults to
'/'. Leading and trailing slashes are normalised automatically, so 'ui', '/ui', and '/ui/' are all equivalent.Optional predicate called for each file before it is registered. Return
true to skip a file. The first argument is the file name; the second is the absolute path of the containing directory.Return value
undefined. Routes are registered as a side effect on proxy.
Behaviour
- Recursive: subdirectories are traversed automatically. A file at
staticDir/js/app.jswithrootPath='/'is served at/js/app.js. - index.html shortcut: when a file named
index.htmlis encountered, it is also registered at the parent directory path (e.g./subdir/), mirroring standard web server behaviour. - MIME detection: content types are set via the
mimepackage based on the file extension. - Forbidden routes: the following paths are reserved by hammerhead and rammerhead. Mounting a file that would clash with one of them throws a
TypeError:
Example
Config integration
Inconfig.js, the publicDir option points to the directory that Rammerhead serves by default:
addStaticFilesToProxy(proxy, config.publicDir) to mount that directory at /. Set publicDir to null to disable static file serving entirely.