import serverless from 'serverless-http' ; import { generateServerlessRouter } from 'fhir-works-on-aws-routing' ; import { getFhirConfig , genericResources } from './config' ; const ensureAsyncInit = async ( initPromise ) : Promise < void > => { try { await initPromise ; } catch ( e ) { console . error ( 'Async initialization failed' , e ) ; process . exit ( 1 ) ; } } ; async function asyncServerless ( ) { return serverless ( generateServerlessRouter ( await getFhirConfig ( ) , genericResources ) , { request ( request , event ) { request . user = event . user ; } , } ) ; } const serverlessHandler = asyncServerless ( ) ; exports . handler = async ( event = { } , context = { } ) : Promise < any > => { await ensureAsyncInit ( serverlessHandler ) ; return ( await serverlessHandler ) ( event , context ) ; } ;