ruru
Version:
Grafast-flavoured GraphiQL distribution
53 lines • 2.26 kB
TypeScript
import type { IncomingMessage, ServerResponse } from "node:http";
type PromiseOrDirect<T> = T | Promise<T>;
export interface StaticFile {
content: Buffer;
headers: Record<string, string>;
}
export interface StaticFiles {
[filename: string]: StaticFile;
}
export interface GetStaticFileContext {
/**
* The URL path to the root of the folder from which static files are being
* served; must start and end with a slash.
*/
staticPath: string;
/**
* The URL path that the user has requested; if it's within the `staticPath`
* then we'll look for a matching file.
*/
urlPath: string;
/**
* The content of the `Accept-Encoding` header supplied by the client, if
* any. Hopefully this includes 'br'. If it does not include 'br' then we
* will need to decompress the content before returning it to you, which is
* more expensive.
*/
acceptEncoding: ReadonlyArray<string> | string | undefined;
/**
* Source maps take up a lot more space in memory and aren't essential; by
* setting this to `true` we will not attempt to load source maps into memory
* and will instead return `null`.
*/
disallowDevAssets?: boolean;
}
/**
* Given the `staticPath` (which must end in a `/`) from which Ruru's static
* assets are served over HTTP, and the `urlPath` that the user has requested,
* return the file and its associated headers to be served in response, or null
* if not found.
*
* IMPORTANT: `staticPath` is the URL path, not the filesystem path. It will be
* pruned from the beginning of `urlPath` before looking up the file.
*/
export declare function getStaticFile({ staticPath, urlPath, acceptEncoding, disallowDevAssets, }: GetStaticFileContext): PromiseOrDirect<StaticFile | null>;
/**
* Returns a middleware compatible with Node, Connect, Express and similar that
* will serve Ruru's static files after trimming off the initial `staticPath`
* (which represents the URL path under which static assets are served, and
* _must_ end in a slash).
*/
export declare function serveStatic(staticPath: string): (req: IncomingMessage, res: ServerResponse, next?: (e?: Error) => void) => undefined;
export {};
//# sourceMappingURL=static.d.ts.map