UNPKG

rexuws

Version:

An express-like framework built on top of uWebsocket.js aims at simple codebase and high performance

72 lines (71 loc) 2.44 kB
/// <reference types="node" /> import { ILoggerProvider } from '../../../Logger'; import { DefaultRouter } from '../../../router'; export interface IServeStaticOptions { [key: string]: any; /** * Allow caching files with accepted mime-type. * * Internally use `mmmagic` to get the most exact file's mime-type and transform this value * into Content-Type by mime-types.contentType() method * * If `true` cache all files * * If `false` use mime-types.contentType() only to extract content type from file's extension * @default true */ useCache?: boolean | string | string[]; /** * Specify the maximum size of file which will be eligible for caching * If '-1' skip this policy * * @default 102400 (100kB) */ maxSize?: number; /** * Watch directory for file's changes * * If `true` Asynchronously watch directory change by `chokidar` which will execute an action on the ServeStaticStore * right after such events as `add`, `change`, `unlink` happened in the directory * * If `false` Do nothing which means if there's new file, it will not be served automatically (respose 404 Not Found). For the modified file, * if it has already been cached, the cache version will be served. * * If `onNotFound`When the given path does exist and it couldn't be found the store, * try to serve file directly (res.sendFile) and resave it to the store (if it does not violate caching policies ) * * @default true */ watcher?: boolean | 'onNotFound'; /** * Set Header: Cache-Control: public, max-age=value * * @default 604800 7days */ maxAge?: number; prefix?: string; } interface IFileDataOrDir { mime?: string; isDirectory?: boolean; data?: Buffer; fileSize?: number; lastModified?: string; mtime?: Date; } export declare class StaticServer { static Store: Record<string, Map<string, IFileDataOrDir>>; static Options: IServeStaticOptions; static Config(opts: IServeStaticOptions, logger?: ILoggerProvider): void; private static Logger; private static Watcher; private static FileWatcher; private path; private pathMappers; constructor(path: string); private readFilesOrDir; private static readFileFromPathAndStat; init(): Promise<void>; static GetRouter(): DefaultRouter; } export {};