/// import Router from './Router'; import { Config, RServerConfig, ListenerCallback, Url, Method, Callback, Middleware, CallbackOptions, MiddlewareOptions, RouteId, MiddlewareId, ErrorCallback } from '../@types'; import { AddressInfo } from 'net'; import Wrapper from './Wrapper'; export default class App { private httpServer; private httpsServer; private entryPath; private config; private router; private mountedRouters; private logger; private bodyParser; private activeServers; private closeCallback; private errorCallback; constructor(config: string | Config); /** * returns server intro */ private getServerIntro; /** * resolves and merges the configuration objects */ private resolveConfig; /** * runs the array of route instances until a matched route is found */ private runRoutes; /** * cordinates how routes are executed, including mounted routes */ private cordinateRoutes; /** * perform house keeping */ private onResponseFinish; /** * handle on response error event */ private onResponseError; /** * parse all request data */ private parseRequestData; /** * handle onrequest end event */ private onRequestEnd; /** * handle on request error event */ private onRequestError; /** * handle request data event */ private onRequestData; /** * handles onrequest events */ private onRequest; /** * handle server close event */ private onClose; /** * handles server listening event */ private onListening; /** * handles client error events */ /** * handle server error events. server errors are majorly startup errors, log error and shut server down */ private onServerError; /** * binds all event handlers on the server */ private initServer; /** * returns boolean indicating if the server is listening */ readonly listening: boolean; /** * returns the server instance router */ getRouter(): Router; /** * returns the server instance mounted routers */ getMountedRouters(): Router[]; /** * returns the resolved server config object */ getConfig(): RServerConfig; /** * sets routing base path that gets prepended to all route and middleware urls */ setBasePath(basePath: string): void; /** * sets the app intance callback error handler * @param errorCallback app instance error callback */ setErrorCallback(errorCallback: ErrorCallback): void; /** * stores route rules for http OPTIONS method * * @param url - route url * @param callback - route callback handler * @param options - route configuration object or middleware or array of middlewares */ options(url: Url, callback: Callback, options?: Middleware | Middleware[] | CallbackOptions): number; /** * stores route rules for http HEAD method * * @param url - route url * @param callback - route callback handler * @param options - route configuration object or middleware or array of middlewares */ head(url: Url, callback: Callback, options?: Middleware | Middleware[] | CallbackOptions): number; /** * stores route rules for http GET method * * @param url - route url * @param callback - route callback handler * @param options - route configuration object or middleware or array of middlewares */ get(url: Url, callback: Callback, options?: Middleware | Middleware[] | CallbackOptions): number; /** * stores route rules for http POST method * * @param url - route url * @param callback - route callback handler * @param options - route configuration object or middleware or array of middlewares */ post(url: Url, callback: Callback, options?: Middleware | Middleware[] | CallbackOptions): number; /** * stores route rules for http PUT method * @param url - route url * @param callback - route callback handler * @param options - route configuration object or middleware or array of middlewares */ put(url: Url, callback: Callback, options?: Middleware | Middleware[] | CallbackOptions): number; /** * stores route rules for http DELETE method * * @param url - route url * @param callback - route callback handler * @param options - route configuration object or middleware or array of middlewares */ delete(url: Url, callback: Callback, options?: Middleware | Middleware[] | CallbackOptions): number; /** * stores route rules for all http methods * * @param url - route url * @param callback - route callback handler * @param options - route configuration object or middleware or array of middlewares */ all(url: Url, callback: Callback, options?: Middleware | Middleware[] | CallbackOptions): void; /** * returns a route wrapper for the given url */ route(url: Url): Wrapper; /** * removes a given route * @param id route id */ removeRoute(id: RouteId): boolean; /** * removes a given middleware * @param id middleware id */ removeMiddleware(id: MiddlewareId): boolean; /** * registers a middleware to be called whenever the given url is visited * * @param url - url to apply middleware to. use * to appy to all urls * @param middleware - the middleware or array of middlewares * @param options - middleware configuration option. here, you can specify the http method * that the middleware will run against */ use(url: Url, middleware: Middleware | Middleware[], options?: Method | Method[] | MiddlewareOptions): number; /** * mounts a router to the server instance */ mount(baseUrl: Url, router: Router): void; /** * starts the server at a given port */ listen(port?: number | null, callback?: ListenerCallback, closeCallback?: ListenerCallback): void; /** * closes server * @param callback callback function to execute when connection closes */ close(callback?: ListenerCallback): void; /** * returns http and https server address */ address(): { http: AddressInfo | null; https: AddressInfo | null; }; }