A static server module for toa.
'use strict';
var Toa = require('toa')
var toaStatic = require('toa-static')('examples/static')
use as middleware:
var app = Toa()
app.use(toaStatic)
app.listen(3000)
npm install toa-static
var ToaStatic = require('toa-static')
Return a thunk function.
options.root
(String) - The directory you wish to serve, default toprocess.cwd
.options.index
(String) - By default this module will send "index.html" files in response to a request on a directory. To disable this setfalse
or to supply a new index pass a string.options.etag
(Boolean) - Enable or disable etag generation, defaults totrue
.options.maxAge
(Number) - Cache control max age (ms) for the files, default to24 * 60 * 60 * 30 * 1000
.options.cacheControl
(String) - Optional cache control header. Overridesoptions.maxAge
.options.compress
(Boolean) - When request's accept-encoding include gzip or deflate, files will compressed.options.fileMap
(Object) - Object map of aliases.options.prefix
(String) - The url prefix you wish to serve as static request, default to'/'
.options.prunePrefix
(Boolean) - Prune the prefix from URL path, default tofalse
.options.files
(Array) - files path you wish to serve.options.staticPath
(Function) - Function to return a custom static file path. thecontext
of this function is toa's context.options.maxCacheLength
(Number) - The maximum length of the files cache in bytes. if cache's size > maxCacheLength, then the least recently used (LRU) file will be removed. if maxCacheLength === -1, cache will not be used. if maxCacheLength === 0, there is no limit. , default to0
.
The MIT License (MIT)