import { formatSnapshot } from './live/format' ; import { startServer } from './live/json_server' ; let views = [ ] ; startServer ( ( message ) => { const content = message . content ; const snapshotName = message . snapshotName ; views = views . filter ( s => Date . now ( ) - s . time < 1500 ) ; const index = views . findIndex ( s => s . snapshotName === snapshotName ) ; console . log ( 'Received: ' + message . snapshotName ) ; message . content = formatSnapshot ( content ) ; message . expected = message . expected && formatSnapshot ( message . expected ) ; if ( index >= 0 ) { views [ index ] = message ; } else { views . unshift ( message ) ; } if ( views . length > 5 ) { views . splice ( 4 , 1 ) ; } } ) ; export const liveApi = ( _req , res ) => res . send ( views ) ;