file
handlerAnswers the request using file system.
{
"match": "^/(.*)",
"file": "./$1"
}
Example of mapping with the
file
handler
Capturing groups can be used as substitution parameters
cwd
member (see mappings)
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)
[!WARNING] Folder names are case-sensitively checked (Windows)
Supports Range
HTTP header (only one range)
If the response already owns a statusCode
different from 200
, 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.
async readdir (folderPath)
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
.
async stat (filePath)
This is the asynchronous equivalent of fs.stat. No option is transmitted.
It must return an object equivalent to fs.Stats but limited to :
async createReadStream (filePath, options)
This is the asynchronous equivalent of fs.createReadStream. When options
is specified, it contains only start
and end
.
It must return a readable stream.