@chubbyts/chubbyts-http-static-file
Version:
A minimal static file handler for chubbyts-http-types.
71 lines (53 loc) • 4.47 kB
Markdown
# chubbyts-http-static-file
[](https://github.com/chubbyts/chubbyts-http-static-file/actions?query=workflow%3ACI)
[](https://coveralls.io/github/chubbyts/chubbyts-http-static-file?branch=master)
[](https://dashboard.stryker-mutator.io/reports/github.com/chubbyts/chubbyts-http-static-file/master)
[](https://www.npmjs.com/package/@chubbyts/chubbyts-http-static-file)
[](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-http-static-file)
[](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-http-static-file)
[](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-http-static-file)
[](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-http-static-file)
[](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-http-static-file)
[](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-http-static-file)
[](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-http-static-file)
[](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-http-static-file)
[](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-http-static-file)
[](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-http-static-file)
[](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-http-static-file)
## Description
A minimal static file handler for chubbyts-http-types.
## Requirements
* node: 18
* [@chubbyts/chubbyts-http-error][2]: ^3.0.0
* [@chubbyts/chubbyts-http-types][3]: ^3.0.0
## Installation
Through [NPM](https://www.npmjs.com) as [@chubbyts/chubbyts-http-static-file][1].
```ts
npm i @chubbyts/chubbyts-http-static-file@^3.0.3
```
## Usage
```ts
import { createStaticFileHandler } from '@chubbyts/chubbyts-http-static-file/dist/handler';
import type { ResponseFactory, StreamFromFileFactory } from '@chubbyts/chubbyts-http-types/dist/message-factory';
import { createGetRoute } from '@chubbyts/chubbyts-framework/dist/router/route';
const responseFactory: ResponseFactory = ...;
const streamFromFileFactory: StreamFromFileFactory = ...;
const handler = createStaticFileHandler(
responseFactory,
streamFromFileFactory,
'/path/to/public/directory',
(await import('../src/mimetypes')).default, // typescript / ecmascript module
// require('../src/mimetypes').default, // commonjs (cjs)
);
// 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-http-static-file
[2]: https://www.npmjs.com/package/@chubbyts/chubbyts-http-error
[3]: https://www.npmjs.com/package/@chubbyts/chubbyts-http-types