UNPKG

hastily

Version:

express middleware to simulate fastly cdn

40 lines (39 loc) 1.49 kB
/** * Simulate the [Fastly ImageOpto](https://docs.fastly.com/api/imageopto/) API. * Returns a middleware which attempts to run image responses through `sharp`. */ import { ErrorLogger, Middleware, RequestFilter } from './imageopto-types'; export interface ImageOptoOptions { errorLog?: ErrorLogger; filter: RequestFilter; /** * Hastily detects when the served image has already been optimized by * Hastily or the real Fastly API, by looking for headers. By default, it * disables its own optimizer for such images. Set this to `false` explicitly * to force hastily to re-optimize those images anyway. */ force?: boolean; /** * Set true to disable error logging; the errorLog function will never be * called. */ quiet?: boolean; } export declare const HASTILY_HEADER: { NAME: string; VALUE: string; }; export declare const HASTILY_STREAMABLE_FILETYPES: Set<string>; export declare const HASTILY_STREAMABLE_PATH_REGEXP: RegExp; /** * Use the `sharp.format` manifest to determine if the current request's file * extension matches a format that sharp can stream in to optimize. * @param req {Request} */ export declare const hasSupportedExtension: RequestFilter; /** * Returns a new imageopto middleware for use in Express `app.use()`. * Won't do anything if the Express app isn't already serving images! * */ export declare function imageopto(filterOrOpts: RequestFilter | ImageOptoOptions): Middleware;