import appPromise , { timers } from './app' ; import { clear as clearServerDataTimers } from '@weco/common/server-data' ; const port = process . env . PORT ?? 3000 ; const serverPromise = appPromise . then ( app => { const server = app . listen ( port , ( ) => { console . log ( `> ${ process . env . NODE_ENV || 'development' } ready on http://localhost:${ port }/` ) ; } ) ; const close = ( ) => { server . close ( ) ; } ; server . on ( 'close' , ( ) => { clearServerDataTimers ( ) ; for ( const timer of timers ) { clearInterval ( timer ) ; } process . exit ( 0 ) ; } ) ; process . on ( 'SIGTERM' , close ) ; process . on ( 'SIGINT' , close ) ; return server ; } ) ; export default serverPromise ;