@wooksjs/http-static v0.4.35
Wooks Serve File
!!! This is work-in-progress library, breaking changes are expected !!!
Wooks Serve File is composable static file server for @wooksjs/event-http.
serveFile
returns a readable stream and prepares all the neccessary response headers (like content-length, content-type etc).
- ✅ returns a readable stream
- ✅ prepares all the neccessary response headers (like content-length, content-type etc)
- ✅ can handle etag
- ✅ can handle ranges
Installation
npm install @wooksjs/http-static
Usage
import { serveFile } from '@wooksjs/http-static'
// ...
serveFile(filePath, options)
serveFile options
{
// Any header to add
headers?: Record<string, string>,
// Cache-Control header
cacheControl?: TCacheControl,
// Expires header
expires?: Date | string | number,
// when true a header "Pragma: no-cache" will be added
pragmaNoCache?: boolean,
// the base directory path
baseDir?: string,
// default extension will be added to the filePath
defaultExt?: string,
// when true lists files in directory
listDirectory?: boolean,
// put 'index.html'
// to automatically serve it from the folder
index?: string,
}
Built-in file server example:
import { useRouteParams } from 'wooks'
import { serveFile } from '@wooksjs/http-static'
app.get('static/*', () => {
const { get } = useRouteParams()
return serveFile(get('*'), { cacheControl: { maxAge: '10m' } })
})
cacheControl
here is the same object as used in useSetCacheControl().setCacheControl({ ... })
from @wooksjs/composables
Documentation
To check out docs, visit wooks.moost.org.
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
2 months ago
3 months ago
3 months ago
3 months ago
3 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
5 months ago
5 months ago
5 months ago
5 months ago
6 months ago
7 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
7 months ago
7 months ago
7 months ago
7 months ago
9 months ago
9 months ago
7 months ago
9 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
11 months ago
11 months ago
12 months ago
12 months ago
11 months ago
12 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago