UNPKG

@dechamp/express-auto-route

Version:

An express auto route module which allows routes and middleware to be configured via config file.

42 lines (41 loc) 1.23 kB
import { RequestParamHandler } from "express"; export interface AutoRoutePropsConfigs { routeBasePath?: string; } export interface AutoRouteProps { server: any; callbackHandler: any; configs?: AutoRoutePropsConfigs; } export declare enum Methods { GET = "GET", POST = "POST", HEAD = "HEAD", PUT = "PUT", DELETE = "DELETE", USE = "USE" } export interface Route { id: string; method: Methods; path: string; modulePath: string; requestJsonSchema?: { body: string; }; responseJsonSchema?: string; middleware?: RequestParamHandler[]; } declare class AutoRoute<AutoRouteProps> { private readonly server; private readonly callbackHandler; private readonly configs?; constructor(server: any, callbackHandler: any, configs: any); mount(routes: Route[]): Promise<string[]>; _guardParams(routes: any): void; _addRoute(route: any): Promise<string>; _buildCallback(route: any): Promise<((req: any, res: any, next: any) => any)[]>; _buildMiddlewareCallbacks(middlewares: string[]): Promise<any[]>; _buildMiddlewareCallback(middlewarePath: string): Promise<(req: any, res: any, next: () => any) => any>; } export { AutoRoute };