reserve

file handler

🔝 REserve documentation

Answers the request using file system.

{
  "match": "^/(.*)",
  "file": "./$1"
}

Example of mapping with the file handler

Features

[!WARNING] Folder names are case-sensitively checked (Windows)

Options

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.

Custom File System

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.