import { Server , IncomingMessage , ServerResponse } from 'http' ; import { RequestHandler } from './RequestHandler' ; export class HTTPD { public constructor ( private logger , private server , private requestHandler , private httpPort , private httpTimeoutMs ) { this . server . setTimeout ( this . httpTimeoutMs ) ; this . server . on ( 'clientError' , ( err , socket ) => { if ( err ) { this . logger . error ( `Error handling client error` ) ; } this . logger . info ( `Client request error` ) ; socket . end ( 'HTTP/1.1 400 Bad Request\r\n\r\n' ) ; } ) ; this . server . on ( 'request' , ( req , res ) => { this . logger . debug ( `Received Request` ) ; this . requestHandler . process ( req , res ) ; } ) ; } public start ( ) { this . logger . info ( `Startint on port ${ this . httpPort }` ) ; this . server . listen ( this . httpPort ) ; this . logger . info ( `Server Start listening on port ${ this . httpPort }` ) ; } }