import { ClientRequest , ServerResponse } from "http" ; import { ApplicationFunction } from "probot" ; import sentryApp from "probot/lib/apps/sentry" ; import { logRequestErrors } from "probot/lib/middleware/log-request-errors" ; import { getLandingPage } from "./landing-page" ; import { createProbot , fetchAppName } from "./utils" ; type RequestHandler = ( request : ClientRequest , response : ServerResponse ) => void ; const initializeProbot = ( applicationFn ) => { const probot = createProbot ( ) ; process . on ( "unhandledRejection" , probot . errorHandler as any ) ; const application = probot . load ( applicationFn ) ; probot . load ( sentryApp ) ; probot . server . use ( logRequestErrors ) ; application . route ( "/" ) . get ( "/" , async ( internalRequest , internalResponse ) => { const name = await fetchAppName ( application ) ; internalResponse . statusCode = 200 ; internalResponse . end ( getLandingPage ( name ) ) ; } ) ; return probot ; } ; param applicationFn const toLambda = ( applicationFn ) : RequestHandler => initializeProbot ( applicationFn ) . server ; export { toLambda } ;