Answers the request using file system.
{
"match": "^/(.*)",
"file": "./$1"
}
Example of mapping with the
file
handler
-
Capturing groups can be used as substitution parameters
-
Always relative to the handler's
cwd
member (see mappings)- 🛂 Path traversal is blocked
-
Incoming URL parameters (and hash) are removed when resolving to file system names
-
Directory access is mapped to the inner
index.html
file (if any) -
If the path resolves to a missing / unreadable / invalid file or directory, the handler does not process the request
Warning
Folder names are case-sensitively checked (Windows)
-
Supports
Range
HTTP header (only one range) -
If the response already owns a
statusCode
different from200
, the file handler will keep it -
Only a limited subset of mime types is pre-configured (see mime.json), use
mime-types
to extend
option | type | default | description |
---|---|---|---|
mime-types |
{ [key: string]: string } |
{} |
Dictionary indexed by file extension that overrides mime type resolution. For instance : { "gsf": "application/x-font-ghostscript" } . |
caching-strategy |
'modified' | number |
0 |
Configures caching strategy : • 'modified' : use file last modification date, meaning the response header will contain Last-Modified and the handler reacts to request headers If-Modified-Since and If-Range ,• number : duration (in seconds), based on the response header Cache-Control with max-age ,• 0 : Cache-Control with no-store . |
custom-file-system |
ExternalModule | CustomFileSystem |
undefined |
Provides custom file system API (see below). |
static |
boolean | PunycacheOptions |
depends on custom-file-system |
Cache file system information for performance. When custom-file-system is used, static is false by default (but can be overridden).Otherwise, static is true by default.An object can be used to pass options to the cache handler, see punycache documentation. |
Warning
When static
is enabled, REserve does not expect the files / folders to change. For instance, if the file size changes while its information has been cached, the result might appear corrupted.
Tip
During development, use static
: false
to ensure files are refreshed properly.
The custom file system is an object exposing several asynchronous methods.
This is the asynchronous equivalent of fs.readdir. No option is transmitted.
It must return a promise resolved to an array of names listing the files or folders contained in the folderPath
.
This is the asynchronous equivalent of fs.stat. No option is transmitted.
It must return an object equivalent to fs.Stats but limited to :
This is the asynchronous equivalent of fs.createReadStream. When options
is specified, it contains only start
and end
.
It must return a readable stream.