@powership/server
Version:
18 lines (17 loc) • 1.02 kB
TypeScript
import type { CloseResponseFunction, Handler, Server } from './Server';
import type { ServerRequest } from './ServerRequest';
import type { ServerResponse } from './ServerResponse';
import type { GetRouteParams } from './routeMatch';
export type RouteHandlerContext<Path extends string = string> = {
path: Path;
request: ServerRequest;
response: ServerResponse;
close: CloseResponseFunction;
app: Server;
params: GetRouteParams<Path>;
};
export interface RouteHandlerCallback<Path extends string> {
(this: RouteHandlerContext<Path>, context: RouteHandlerContext<Path>): any;
}
export declare function createRouteHandler<Path extends string, Callback extends RouteHandlerCallback<Path>>(path: Path, handler: RouteHandlerCallback<Path>): Handler<undefined>;
export declare function createRouteHandler<Path extends string, Callback extends RouteHandlerCallback<Path>, StaticData extends Record<string, any>>(path: Path, handler: RouteHandlerCallback<Path>, data: StaticData): Handler<StaticData>;