@nx.js/http
Version:
HTTP server for nx.js
38 lines (37 loc) • 1.2 kB
TypeScript
/**
* Options object for the {@link createStaticFileHandler | `createStaticFileHandler()`} function.
*/
export interface StaticFileHandlerOptions {
/**
* Addional HTTP headers to include in the response. Can be a static
* `Headers` object, or a function which returns a `Headers` object.
*/
headers?: HeadersInit | ((req: Request, path: URL) => HeadersInit);
}
export declare function resolvePath(url: string, root: string): URL;
/**
* Creates an HTTP handler function which serves file contents from the filesystem.
*
* @example
*
* ```typescript
* import { createStaticFileHandler, listen } from '@nx.js/http';
*
* const fileHandler = createStaticFileHandler('sdmc:/switch/');
*
* listen({
* port: 8080,
* async fetch(req) {
* let res = await fileHandler(req);
* if (!res) {
* res = new Response('File not found', { status: 404 });
* }
* return res;
* }
* });
* ```
*
* @param root Root directory where static files are served from
* @param opts Optional options object
*/
export declare function createStaticFileHandler(root: Switch.PathLike, opts?: StaticFileHandlerOptions): (req: Request) => Promise<Response | null>;