ziron-server
Version:
47 lines (46 loc) • 1.42 kB
TypeScript
import { HttpRequest } from "ziron-ws";
import { HttpResponse as HttpResponse } from "./EnhanceHttpResponse";
/**
* @description
* Simple helper class to serve static files.
*/
export default class StaticFilesRouter {
private readonly files;
customContentTypeResolutionMap: Record<string, string>;
/**
* @description
* Serves a static file.
* @example
* file("dist/style.css","/myStyles/styles.css")
* @param pattern
* @param filePath
* @param override
*/
file(filePath: string, pattern?: string, override?: boolean): void;
/**
* @description
* Serves a folder recursive.
* @example
* folder("dist/assets","someAssets")
* @param folder
* @param urlPath
* @param options
*/
folder(folder: string, urlPath?: string, options?: {
filter?: (file: string) => boolean;
linkIndex?: boolean;
override?: boolean;
}): void;
/**
* @description
* Handles the incoming request.
* Returns false when the response cannot be handled or a
* truthy value when the response can be handled.
* The truthy value is a promise and rejected errors needs to be handled.
* It resolves when the file writing has been finished or
* is resolved on a redirect.
* @param req
* @param res
*/
handle(req: HttpRequest, res: HttpResponse): false | Promise<void>;
}