@@ -123,12 +123,8 @@ const server = http.createServer(async (req, res) => {
123123 attributes : body . attributes || { } ,
124124 received_at : new Date ( ) . toISOString ( ) ,
125125 } ;
126- if ( ev . event_type === 'demo.reset' ) {
127- events = [ ] ;
128- } else {
129- events . push ( ev ) ;
130- if ( events . length > MAX_EVENTS ) events = events . slice ( - MAX_EVENTS ) ;
131- }
126+ events . push ( ev ) ;
127+ if ( events . length > MAX_EVENTS ) events = events . slice ( - MAX_EVENTS ) ;
132128 broadcastEvent ( ev ) ;
133129 return sendJson ( res , 200 , { } ) ;
134130 }
@@ -138,12 +134,8 @@ const server = http.createServer(async (req, res) => {
138134 const body = await parseBody ( req ) ;
139135 for ( const ev of translateOtlpLogs ( body ) ) {
140136 ev . received_at = new Date ( ) . toISOString ( ) ;
141- if ( ev . event_type === 'demo.reset' ) {
142- events = [ ] ;
143- } else {
144- events . push ( ev ) ;
145- if ( events . length > MAX_EVENTS ) events = events . slice ( - MAX_EVENTS ) ;
146- }
137+ events . push ( ev ) ;
138+ if ( events . length > MAX_EVENTS ) events = events . slice ( - MAX_EVENTS ) ;
147139 broadcastEvent ( ev ) ;
148140 }
149141 return sendJson ( res , 200 , { partialSuccess : { } } ) ;
@@ -228,48 +220,6 @@ const server = http.createServer(async (req, res) => {
228220 }
229221 }
230222
231- // POST /api/reset - proxy to demo-admin reset endpoint
232- if ( pathName === '/api/reset' && method === 'POST' ) {
233- const adminHost = process . env . ADMIN_HOST || 'demo-admin' ;
234- const adminPort = process . env . ADMIN_PORT || '8080' ;
235- return new Promise ( ( resolve ) => {
236- let responded = false ;
237- const proxyReq = http . request ( {
238- hostname : adminHost ,
239- port : parseInt ( adminPort ) ,
240- path : '/api/reset' ,
241- method : 'POST' ,
242- headers : { 'Content-Type' : 'application/json' } ,
243- timeout : 30000 ,
244- } , ( proxyRes ) => {
245- let body = '' ;
246- proxyRes . on ( 'data' , chunk => { body += chunk ; } ) ;
247- proxyRes . on ( 'end' , ( ) => {
248- if ( responded ) return ;
249- responded = true ;
250- events = [ ] ;
251- res . writeHead ( proxyRes . statusCode , { 'Content-Type' : 'application/json' } ) ;
252- res . end ( body ) ;
253- resolve ( ) ;
254- } ) ;
255- } ) ;
256- proxyReq . on ( 'error' , ( err ) => {
257- if ( responded ) return ;
258- responded = true ;
259- sendJson ( res , 502 , { error : 'Failed to reach demo-admin: ' + err . message } ) ;
260- resolve ( ) ;
261- } ) ;
262- proxyReq . on ( 'timeout' , ( ) => {
263- proxyReq . destroy ( ) ;
264- if ( responded ) return ;
265- responded = true ;
266- sendJson ( res , 504 , { error : 'demo-admin request timed out' } ) ;
267- resolve ( ) ;
268- } ) ;
269- proxyReq . end ( ) ;
270- } ) ;
271- }
272-
273223 // Serve static files for everything else
274224 serveStatic ( req , res ) ;
275225 } catch ( e ) {
@@ -283,8 +233,9 @@ const wss = new WebSocketServer({ server, path: '/ws' });
283233wss . on ( 'connection' , ( ws ) => {
284234 wsClients . add ( ws ) ;
285235
286- // Send event history on connect
287- ws . send ( JSON . stringify ( { type : 'history' , events } ) ) ;
236+ // Send event history on connect, sorted chronologically
237+ const sortedEvents = [ ...events ] . sort ( ( a , b ) => ( a . timestamp < b . timestamp ? - 1 : a . timestamp > b . timestamp ? 1 : 0 ) ) ;
238+ ws . send ( JSON . stringify ( { type : 'history' , events : sortedEvents } ) ) ;
288239
289240 ws . on ( 'close' , ( ) => {
290241 wsClients . delete ( ws ) ;
0 commit comments