@visulima/ono
Version:
Ono is an error-parsing library that pretty prints JavaScript errors on a web page or the terminal.
30 lines (29 loc) • 1.29 kB
TypeScript
import type { IncomingMessage, ServerResponse } from "node:http";
type RequestBody = Record<string, unknown>;
type UniversalHandler = (request: IncomingMessage & {
body?: RequestBody;
}, response: ServerResponse, next?: (error?: unknown) => void) => Promise<void>;
type NodeHttpHandler = (request: IncomingMessage & {
body?: RequestBody;
}, response: ServerResponse) => Promise<void>;
export type OpenInEditorOptions = {
allowOutsideProject?: boolean;
projectRoot?: string;
};
/**
* Single universal handler factory for Node HTTP and Connect/Express.
* Accepts POST JSON or GET query (?file&line&column&editor).
* Enforces projectRoot unless allowOutsideProject is true.
* @example
* ```typescript
* const openInEditor = createOpenInEditorMiddleware({ projectRoot: process.cwd() })
* // Node http
* if (url.pathname === '/__open-in-editor') return openInEditor(req, res)
* // Express/Connect
* app.post('/__open-in-editor', openInEditor)
* ```
*/
export declare const createOpenInEditorMiddleware: (options?: OpenInEditorOptions) => UniversalHandler;
export declare const createNodeHttpHandler: (options?: OpenInEditorOptions) => NodeHttpHandler;
export declare const createExpressHandler: (options?: OpenInEditorOptions) => UniversalHandler;
export {};