/// import { EventEmitter } from 'events'; import express from 'express'; import * as http from 'http'; import * as https from 'https'; export interface IHTTPSConfig { key: string; cert: string; } export interface IListnerConfig { host?: string; port?: number; secure?: boolean; } export declare type IMiddleware = (req: express.Request, res: express.Response, next?: Function) => void; export interface IServerHeadersConfig { noCache?: boolean; frameGuard?: boolean; xssFilter?: boolean; maskPoweredBy?: boolean; } export interface IServerConfig extends IListnerConfig { basicAuthParser?: boolean; jsonBodyParser?: boolean; secureHeaders?: IServerHeadersConfig; httpsConfig?: IHTTPSConfig; } export interface IRouteConfig { method?: string; path: string; handler: IMiddleware; } export interface IBasicAuthInfo { username: string; password: string; } export interface IAppLocals { appId: string; } export interface IResponseLocals { auth: { header: string; username: string; password: string; }; } export declare type IEventListener = (...args: any[]) => void; /** * Express.js-based application server */ export declare class Server extends EventEmitter { private serverConfig; private readonly app; /** * Construct a server instance */ constructor(customServerConfig?: IServerConfig); /** * Get server configuration */ getServerConfig(): IServerConfig; /** * Configure SSL/TLS credentials for HTTPS * @param httpsConfig HTTPS configuration */ setHTTPSCredentials(httpsConfig: IHTTPSConfig): Server; /** * Start the server * @param listenerConfig Server listener configuration */ listen(listenerConfig: IListnerConfig): (http.Server | https.Server); /** * Convenient function to register more than one route * @param routeConfig Route configuration */ routes(routeConfig: IRouteConfig[]): Server; /** * Define a route * @param routeConfig Route configuration */ route(routeConfig: IRouteConfig): Server; /** * Define a server middleware * @param middlewareFn Middleware function */ middleware(middlewareFn: IMiddleware): Server; /** * Parse HTTP basic authorization header if exists * @param req HTTP Request object * @param res HTTP Response object * @param next Function to call the next middleware */ private parseBasicAuthHeader; /** * Internal function to configure routes * @param routeConfig Route configuration */ private registerRoute; }