///
import * as http from "http";
export interface IRequestContext {
path: string;
method: string;
params: {
[key: string]: string;
};
query: {
[key: string]: string | string[] | undefined;
};
headers: http.IncomingHttpHeaders;
payload?: any;
auth?: any;
attachment?: string;
status?: number;
body?: any;
buffer?: string;
type?: string;
}
export declare type RequestHandler = (ctx: IRequestContext, next?: () => Promise) => Promise;
export interface IParam {
name: string;
index: number;
}
export interface IRoute {
method: string;
path: string;
handlers: RequestHandler[];
params: IParam[];
}
export declare class Router {
prefix: string;
routes: IRoute[];
extantions: Router[];
constructor(prefix?: string);
attach(router: Router): void;
inject(httpServer: http.Server): void;
callback(): (req: http.IncomingMessage, res: http.ServerResponse) => void;
has(reqMethod: string, reqUrl: string): IRoute | null;
exec(route: IRoute, req: http.IncomingMessage, res: http.ServerResponse): void;
addRoute(method: string, path: string, handlers: RequestHandler[]): this;
get(path: string, ...handlers: RequestHandler[]): this;
post(path: string, ...handlers: RequestHandler[]): this;
delete(path: string, ...handlers: RequestHandler[]): this;
static send(...paths: string[]): (ctx: IRequestContext) => Promise;
static static(path: string): Router;
}