@longjs/static
Introduction
The module based on @longjs/core, used for HTTP static file output.
Use
> yarn add @longjs/staticor
> npm install @longjs/staticExamples
import Server from '@longjs/core'
import StaticServer from '@longjs/static'
// If your want to use redis.
new Server({
port: 3000,
plugins: [
new StaticServer({
root: resolve('public'),
maxage: 60000,
defer: true
})
]
})Api
Options
maxageBrowser cache max-age in milliseconds. defaults to 0hiddenAllow transfer of hidden files. defaults to falseindexDefault file name, defaults to 'index.html'deferIf true, serves is responding after controllersgzipTry to serve the gzipped version of a file automatically when gzip is supported by a client and if the requested file with .gz extension exists. defaults to true.brTry to serve the brotli version of a file automatically when brotli is supported by a client and if the requested file with .br extension exists (note, that brotli is only accepted over https). defaults to true.setHeadersFunction to set custom headers on response.extensionsTry to match extensions from passed array to search for file when no extension is sufficed in URL. First found is served. (defaults tofalse)
setHeaders
The function is called as fn(res, path, stats), where the arguments are:
res: the response objectpath: the resolved file path that is being sentstats: the stats object of the file that is being sent.
You should only use the setHeaders option when you wish to edit the Cache-Control or Last-Modified headers, because doing it before is useless (it's overwritten by send), and doing it after is too late because the headers are already sent.
If you want to edit any other header, simply set them before calling send.