@chubbyts/chubbyts-undici-static-file
Version:
A minimal static file handler for chubbyts-undici-server
64 lines (47 loc) • 4.19 kB
Markdown
# chubbyts-undici-static-file
[](https://github.com/chubbyts/chubbyts-undici-static-file/actions?query=workflow%3ACI)
[](https://coveralls.io/github/chubbyts/chubbyts-undici-static-file?branch=master)
[](https://dashboard.stryker-mutator.io/reports/github.com/chubbyts/chubbyts-undici-static-file/master)
[](https://www.npmjs.com/package/@chubbyts/chubbyts-undici-static-file)
[](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-undici-static-file)
[](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-undici-static-file)
[](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-undici-static-file)
[](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-undici-static-file)
[](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-undici-static-file)
[](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-undici-static-file)
[](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-undici-static-file)
[](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-undici-static-file)
[](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-undici-static-file)
[](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-undici-static-file)
[](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-undici-static-file)
## Description
A minimal static file handler for chubbyts-undici-server.
## Requirements
* node: 20
* [@chubbyts/chubbyts-http-error][2]: ^3.0.1
* [@chubbyts/chubbyts-undici-server][3]: ^1.0.0
## Installation
Through [NPM](https://www.npmjs.com) as [@chubbyts/chubbyts-undici-static-file][1].
```ts
npm i @chubbyts/chubbyts-undici-static-file@^1.0.0
```
## Usage
```ts
import { createStaticFileHandler } from '@chubbyts/chubbyts-undici-static-file/dist/handler';
import { createGetRoute } from '@chubbyts/chubbyts-framework/dist/router/route';
const handler = createStaticFileHandler(
'/path/to/public/directory',
(await import('../src/mimetypes')).default,
);
// for example as a fallback route matching everything
const route = createGetRoute({
path: '/*path',
name: 'static_file',
handler,
});
```
## Copyright
2025 Dominik Zogg
[1]: https://www.npmjs.com/package/@chubbyts/chubbyts-undici-static-file
[2]: https://www.npmjs.com/package/@chubbyts/chubbyts-http-error
[3]: https://www.npmjs.com/package/@chubbyts/chubbyts-undici-server