UNPKG

http-micro

Version:

Micro-framework on top of node's http module

50 lines (49 loc) 2.04 kB
/// <reference types="node" /> import { NextMiddleware, Middleware } from "./core"; import { Context } from "./context"; import { Router } from "./router"; import * as net from "net"; import * as http from "http"; /** * The default error handler. It's executed at the end of * the middleware chain or whenever, an exception that's * not caught by the application is encountered. * * @export * @param {Error} err */ export declare function defaultErrorHandler(err: Error, req: http.IncomingMessage, res: http.ServerResponse): void; /** * A default fall-back handler that simply ends the request, and returns. * * @export * @param {IContext} context * @param {MiddlewareWithContext} next * @returns {Promise} Resolved Promise */ export declare function defaultFallbackOkHandler(context: Context, next: NextMiddleware): Promise<void>; /** * The default fall-back handler that ends the request with 404 status code. * * @export * @param {IContext} context * @param {MiddlewareWithContext} next * @returns {Promise} Resolved Promise */ export declare function defaultFallbackNotFoundHandler(context: Context, next: NextMiddleware): Promise<void>; export declare function defaultClientSocketErrorHandler(err: any, socket: net.Socket): void; /** * Composes multiple middlewares into one middleware that executes the middleware chain. * * @export * @template T {IContext} * @param {...Middleware<T>[]} middlewares * @returns {Middleware<T>} */ export declare function compose(...middlewares: Middleware<any>[]): Middleware<any>; export declare function dispatch(context: Context, next: NextMiddleware, middlewares: Middleware<any>[]): Promise<void>; /** * Stringify JSON, like JSON.stringify, but v8 optimized. */ export declare function stringify(value: any, replacer: (key: string, value: any) => any, spaces: string | number): string; export declare function addMiddlewares(middlewares: (Middleware<any> | Router<any>)[], destination: Middleware<any>[]): void;