UNPKG

alepha

Version:

Easy-to-use modern TypeScript framework for building many kind of applications.

126 lines 3.58 kB
import { Alepha, KIND, Primitive } from "alepha"; import { ServerHandler, ServerRouterProvider } from "alepha/server"; import { DateTimeProvider, DurationLike } from "alepha/datetime"; import { FileDetector } from "alepha/system"; //#region ../../src/server/static/primitives/$serve.d.ts /** * Create a new static file handler. */ declare const $serve: { (options?: ServePrimitiveOptions): ServePrimitive; [KIND]: typeof ServePrimitive; }; interface ServePrimitiveOptions { /** * Prefix for the served path. * * @default "/" */ path?: string; /** * Path to the directory to serve. * * @default process.cwd() */ root?: string; /** * If true, primitive will be ignored. * * @default false */ disabled?: boolean; /** * Whether to keep dot files (e.g. `.gitignore`, `.env`) in the served directory. * * @default true */ ignoreDotEnvFiles?: boolean; /** * Whether to use the index.html file when the path is a directory. * * @default true */ indexFallback?: boolean; /** * Force all requests "not found" to be served with the index.html file. * This is useful for single-page applications (SPAs) that use client-side only routing. */ historyApiFallback?: boolean; /** * Optional name of the primitive. * This is used for logging and debugging purposes. * * @default Key name. */ name?: string; /** * Whether to use cache control headers. * * @default {} */ cacheControl?: Partial<CacheControlOptions> | false; /** * Whether to suppress logging for this primitive. * * @default false */ silent?: boolean; } interface CacheControlOptions { /** * Whether to use cache control headers. * * @default [.js, .css] */ fileTypes: string[]; /** * The maximum age of the cache in seconds. * * @default 60 * 60 * 24 * 2 // 2 days */ maxAge: DurationLike; /** * Whether to use immutable cache control headers. * * @default true */ immutable: boolean; } declare class ServePrimitive extends Primitive<ServePrimitiveOptions> {} //#endregion //#region ../../src/server/static/providers/ServerStaticProvider.d.ts declare class ServerStaticProvider { protected readonly alepha: Alepha; protected readonly routerProvider: ServerRouterProvider; protected readonly dateTimeProvider: DateTimeProvider; protected readonly fileDetector: FileDetector; protected readonly log: import("alepha/logger").Logger; protected readonly directories: ServeDirectory[]; protected readonly configure: import("alepha").HookPrimitive<"configure">; createStaticServer(options: ServePrimitiveOptions): Promise<void>; createFileHandler(filepath: string, options: ServePrimitiveOptions): Promise<ServerHandler>; protected getCacheFileTypes(): string[]; protected getCacheControl(filename: string, options: ServePrimitiveOptions): { maxAge: number; immutable: boolean; } | undefined; getAllFiles(dir: string, ignoreDotEnvFiles?: boolean): Promise<string[]>; } interface ServeDirectory { options: ServePrimitiveOptions; files: string[]; } //#endregion //#region ../../src/server/static/index.d.ts /** * Static file serving. * * **Features:** * - Serve static files from directory * * @module alepha.server.static */ declare const AlephaServerStatic: import("alepha").Service<import("alepha").Module>; //#endregion export { $serve, AlephaServerStatic, CacheControlOptions, ServeDirectory, ServePrimitive, ServePrimitiveOptions, ServerStaticProvider }; //# sourceMappingURL=index.d.ts.map