UNPKG

@webda/core

Version:

Expose API with Lambda

83 lines (82 loc) 1.82 kB
import { WebContext } from "../utils/context.js"; import { Service, ServiceParameters } from "./service.js"; /** * ResourceService parameters */ export declare class ResourceServiceParameters extends ServiceParameters { /** * URL on which to serve the content * * @default "resources" */ url?: string; /** * Folder to server * * @default "." + url */ folder?: string; /** * Add the / root to redirect to /{url} * * @default false */ rootRedirect?: boolean; /** * Index file * * @default index.html */ index?: string; /** * Return the index file for any unfound resource * Useful for single page application * * @default true */ indexFallback?: boolean; constructor(params: any); } /** * This service expose a folder as web * * It is the same as `static` on `express` * * @category CoreServices * @WebdaModda */ export default class ResourceService<T extends ResourceServiceParameters = ResourceServiceParameters> extends Service<T> { /** * Resolved path to the folder to serve */ _resolved: string; /** * If serving just one file */ fileOnly: boolean; /** * Load the parameters for a service */ loadParameters(params: any): ResourceServiceParameters; /** * Resolve resource folder */ computeParameters(): void; /** * Init the routes */ initRoutes(): void; /** * Handle / request and redirect to the resources folder * * @param ctx */ _redirect(ctx: WebContext): void; /** * Serve the folder by itself, doing the mime detection * * @param ctx */ _serve(ctx: WebContext): Promise<unknown>; } export { ResourceService };