UNPKG

alepha

Version:

Alepha is a convention-driven TypeScript framework for building robust, end-to-end type-safe applications, from serverless APIs to full-stack React apps.

119 lines (118 loc) 3.41 kB
import * as _alepha_core1 from "alepha"; import { Alepha, Descriptor, KIND } from "alepha"; import { ServerHandler, ServerRouterProvider } from "alepha/server"; import { DateTimeProvider, DurationLike } from "alepha/datetime"; import * as _alepha_logger0 from "alepha/logger"; //#region src/descriptors/$serve.d.ts /** * Create a new static file handler. */ declare const $serve: { (options?: ServeDescriptorOptions): ServeDescriptor; [KIND]: typeof ServeDescriptor; }; interface ServeDescriptorOptions { /** * Prefix for the served path. * * @default "/" */ path?: string; /** * Path to the directory to serve. * * @default process.cwd() */ root?: string; /** * If true, descriptor 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 descriptor. * This is used for logging and debugging purposes. * * @default Key name. */ name?: string; /** * Whether to use cache control headers. * * @default {} */ cacheControl?: Partial<CacheControlOptions> | false; } 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 ServeDescriptor extends Descriptor<ServeDescriptorOptions> {} //#endregion //#region src/providers/ServerStaticProvider.d.ts declare class ServerStaticProvider { protected readonly alepha: Alepha; protected readonly routerProvider: ServerRouterProvider; protected readonly dateTimeProvider: DateTimeProvider; protected readonly log: _alepha_logger0.Logger; protected readonly directories: ServeDirectory[]; protected readonly configure: _alepha_core1.HookDescriptor<"configure">; createStaticServer(options: ServeDescriptorOptions): Promise<void>; createFileHandler(filepath: string, options: ServeDescriptorOptions): Promise<ServerHandler>; protected getCacheFileTypes(): string[]; protected getCacheControl(filename: string, options: ServeDescriptorOptions): { maxAge: number; immutable: boolean; } | undefined; getAllFiles(dir: string, ignoreDotEnvFiles?: boolean): Promise<string[]>; } interface ServeDirectory { options: ServeDescriptorOptions; files: string[]; } //#endregion //#region src/index.d.ts /** * Create static file server with `$static()`. * * @see {@link ServerStaticProvider} * @module alepha.server.static */ declare const AlephaServerStatic: _alepha_core1.Service<_alepha_core1.Module<{}>>; //#endregion export { $serve, AlephaServerStatic, CacheControlOptions, ServeDescriptor, ServeDescriptorOptions, ServeDirectory, ServerStaticProvider }; //# sourceMappingURL=index.d.ts.map