/// import { RemoteCli } from '../services/remoteCli.service'; import { Logger } from '../../common/services/logger.service'; import { Server as Hapi } from 'hapi'; import { Response } from '../controllers/response'; import { Request } from '../controllers/request'; import { PromiseFactory } from '../../common/util/serialPromise'; import { Application as Express } from 'express'; import { Server as HttpServer } from 'http'; export declare type HttpMethod = 'GET' | 'PUT' | 'PATCH' | 'POST' | 'DELETE'; export interface RouteConfig { path: string; methodName: string; method: HttpMethod; callStack: PromiseFactory[]; callStackHandler: (request: Request, response: Response) => Promise; } /** * Root class that all implementations of server *must* extends. Provides common interface for * bootstrapper to handle server startup without caring about underlying implementation */ export declare abstract class Server { /** Hostname eg `localhost`, `example.com` */ protected host: string; /** Port number server is running on */ protected port: number; /** `require('http').Server` object from the base class */ protected httpServer: HttpServer; /** All Configured routes */ configuredRoutes: RouteConfig[]; /** Logger instance for the class, initialized with `server` source */ protected logger: Logger; constructor(loggerBase: Logger, remoteCli: RemoteCli); /** * Registration function for routes * @param config */ register(config: RouteConfig): this; /** * Register the defined route with the engine * @param config */ protected abstract registerRouteWithEngine(config: RouteConfig): this; /** * Initialization function, called before start is called */ protected abstract initialize(): this; /** * Kicks off the server using the specific underlying engine */ abstract startEngine(): Promise; /** * Register loader with engine to handle static loading of frontend assets * @param webroot */ abstract registerStaticLoader(webroot: string): this; /** * Kicks off the server */ start(): Promise; /** * Retrieves the underlying engine for custom calls * @returns {Hapi|any} */ abstract getEngine(): Hapi | Express | any; /** * Retrieve the base instance of require('http').Server * @returns {HttpServer} */ getHttpServer(): HttpServer; /** * Get the host name (for logging) * @returns {string} */ getHost(): string; /** * Retrieve all configured routes * @returns {RouteConfig[]} */ getRoutes(): RouteConfig[]; /** * Get the default response object * @returns {Response} */ protected getDefaultResponse(): Response; }