@chubbyts/chubbyts-http-static-file

2.0.1 • Public • Published

chubbyts-http-static-file

CI Coverage Status Mutation testing badge npm-version

bugs code_smells coverage duplicated_lines_density ncloc sqale_rating alert_status reliability_rating security_rating sqale_index vulnerabilities

Description

A minimal static file handler for chubbyts-http-types.

Requirements

Installation

Through NPM as @chubbyts/chubbyts-http-static-file.

npm i @chubbyts/chubbyts-http-static-file@^2.0.1

Usage

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

2024 Dominik Zogg

Package Sidebar

Install

npm i @chubbyts/chubbyts-http-static-file

Weekly Downloads

6

Version

2.0.1

License

MIT

Unpacked Size

93.9 kB

Total Files

9

Last publish

Collaborators

  • dominikzogg