import { Binding , BindingScope , Context , inject , injectable , } from '@loopback/core' ; import { get , RequestContext , ResponseObject , RestBindings , } from '@loopback/rest' ; import { LOGGER_SERVICE } from '../keys' ; import { bindingScope , count , logContext , logContexts , Logger } from '../util' ; /**
 * OpenAPI response for ping()
 */ const PING_RESPONSE = { description : 'Ping Response' , content : { 'application/json' : { schema : { type : 'object' , title : 'PingResponse' , properties : { greeting : { type : 'string' } , date : { type : 'string' } , url : { type : 'string' } , headers : { type : 'object' , properties : { 'Content-Type' : { type : 'string' } , } , additionalProperties : true , } , } , } , } , } , } ; /**
 * A simple controller to bounce back http requests
 */ @ injectable ( { scope : bindingScope ( 'PingController' , BindingScope . TRANSIENT ) } ) export class PingController { constructor ( @ inject . context ( ) resolutionCtx , @ inject . binding ( ) private binding , @ inject ( LOGGER_SERVICE ) private logger ) { logContexts ( resolutionCtx , binding , this . logger ) ; } @ get ( '/ping' , { responses : { '200' : PING_RESPONSE , } , } ) async ping ( @ inject ( RestBindings . Http . CONTEXT ) requestCtx ) { logContext ( 'Request' , requestCtx , this . binding , this . logger ) ; await count ( requestCtx , 'PingController' ) ; const result = { greeting : 'Hello from LoopBack' , date : new Date ( ) , url : requestCtx . request . url , headers : { ... requestCtx . request . headers } , } ; this . logger ( 'Response' , result ) ; return result ; } }