@longjs/static
v1.0.3
Published
[![npm (scoped)](https://img.shields.io/npm/v/@longjs/static.svg)](https://www.npmjs.com/package/@longjs/static)
Downloads
14
Maintainers
Readme
@longjs/static
Introduction
The module based on @longjs/core, used for HTTP static file output.
Use
> yarn add @longjs/static
or
> npm install @longjs/static
Examples
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
maxage
Browser cache max-age in milliseconds. defaults to 0hidden
Allow transfer of hidden files. defaults to falseindex
Default file name, defaults to 'index.html'defer
If true, serves is responding after controllersgzip
Try 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.br
Try 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.setHeaders
Function to set custom headers on response.extensions
Try 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
.