https://github.com/chubbyts/chubbyts-http-static-file
A minimal static file handler for chubbyts-http-types.
https://github.com/chubbyts/chubbyts-http-static-file
chubbyts handler psr-7 static-file
Last synced: 3 months ago
JSON representation
A minimal static file handler for chubbyts-http-types.
- Host: GitHub
- URL: https://github.com/chubbyts/chubbyts-http-static-file
- Owner: chubbyts
- License: mit
- Created: 2023-03-26T20:14:25.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2025-03-04T13:00:16.000Z (4 months ago)
- Last Synced: 2025-03-25T00:29:01.264Z (4 months ago)
- Topics: chubbyts, handler, psr-7, static-file
- Language: TypeScript
- Homepage:
- Size: 57.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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]: ^2.4.1
* [@chubbyts/chubbyts-http-types][3]: ^1.3.1 || ^2.0.0## Installation
Through [NPM](https://www.npmjs.com) as [@chubbyts/chubbyts-http-static-file][1].
```ts
npm i @chubbyts/chubbyts-http-static-file@^2.2.0
```## 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: '/(.*)',
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