Skip to content

chubbyts/chubbyts-http-static-file

Repository files navigation

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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published