import type { EngineOptions, FetchEvent, FetchHandler, Handlers, ListenOptions, NextFunction, RetHandler, TApp, TObject, TRet } from "./types"; import Router, { type TRouter } from "./router"; import { RequestEvent } from "./request_event"; export declare class NHttp extends Router { private parseQuery; private env; private stackError; private bodyParser?; server: TRet; constructor({ parseQuery, bodyParser, env, stackError }?: TApp); /** * global error handling. * @example * app.onError((err, rev) => { * return err.message; * }) */ onError(fn: (err: TObject, rev: Rev, next: NextFunction) => RetHandler): this; /** * global not found error handling. * @example * app.on404((rev) => { * return `route ${rev.url} not found`; * }) */ on404(fn: (rev: Rev, next: NextFunction) => RetHandler): this; on(method: string, path: string | RegExp, ...handlers: Handlers): this; /** * engine - add template engine. * @example * app.engine(ejs.renderFile, { base: "public", ext: "ejs" }); * * app.get("/", async ({ response }) => { * await response.render("index", { title: "hello ejs" }); * }); */ engine(render: ((...args: TRet) => TRet) & { check?: (elem: TRet) => boolean; }, opts?: EngineOptions): this; matchFns: (rev: RequestEvent, method: string, url: string) => import("./types").Handler[]; private onErr; /** * handleRequest * @example * Deno.serve(app.handleRequest); * // or * Bun.serve({ fetch: app.handleRequest }); */ handleRequest: FetchHandler; /** * handle * @example * Deno.serve(app.handle); * // or * Bun.serve({ fetch: app.handle }); */ handle: FetchHandler; /** * handleEvent * @example * addEventListener("fetch", (event) => { * event.respondWith(app.handleEvent(event)) * }); */ handleEvent: (evt: FetchEvent) => Response | Promise; /** * Mock request. * @example * app.get("/", () => "hello"); * app.post("/", () => "hello, post"); * * // mock request * const hello = await app.req("/").text(); * assertEquals(hello, "hello"); * * // mock request POST * const hello_post = await app.req("/", { method: "POST" }).text(); * assertEquals(hello_post, "hello, post"); */ req: (url: string, init?: RequestInit) => { text: () => Promise; json: () => Promise; ok: () => Promise; status: () => Promise; res: () => Response | Promise; }; /** * listen the server * @example * app.listen(8000); * app.listen({ port: 8000, hostname: 'localhost' }); * app.listen({ * port: 443, * cert: "./path/to/my.crt", * key: "./path/to/my.key", * alpnProtocols: ["h2", "http/1.1"] * }, callback); */ listen: (options: number | ListenOptions, callback?: (err: Error | undefined, opts: ListenOptions) => void | Promise) => any; private _onError; private _on404; } /** * inital app. * @example * const app = nhttp(); */ export declare function nhttp(opts?: TApp): NHttp; export declare namespace nhttp { var Router: = RequestEvent>(opts?: TRouter) => Router; }