tall-sundown-41732
03/22/2023, 11:43 AMtall-sundown-41732
03/22/2023, 11:44 AMgorgeous-airport-54386
03/22/2023, 11:44 AMts
app.get('/track/stream', (req, res) => {
const ticketId = req.query['ticket'] as string
const ticket = validateTicket(ticketId)
if (typeof ticket === 'string') return res.render('err.njk', { error: ticket, bare: true })
const tracker = new RailwayTracker(ticketId, trains, routes, tickets)
// Headers as per Server Sent Events spec
res.setHeader('Cache-Control', 'no-cache')
res.setHeader('Content-Type', 'text/event-stream')
res.setHeader('Connection', 'keep-alive')
res.flushHeaders()
res.write('retry: 8000\n\n')
const onReport = (e: Event) => {
// @ts-ignore
const r = e.detail as TrainReport
console.log('sending')
res.write('event: report\n' +
`data: ${nunjucks.render('track-stream.njk', { report: r })}\n\n`)
}
tracker.addEventListener('report', onReport)
tracker.addEventListener('closed', function listener() {
tracker.removeEventListener('report', onReport)
tracker.removeEventListener('closed', listener)
res.end()
})
})
tall-sundown-41732
03/22/2023, 11:45 AMgorgeous-airport-54386
03/22/2023, 11:46 AMdata:
before every line of the data. I just rewrote my template to all be in one line since I couldn't understand what was happening :]tall-sundown-41732
03/22/2023, 11:49 AMtall-sundown-41732
03/22/2023, 11:49 AMgorgeous-airport-54386
03/22/2023, 11:50 AMtall-sundown-41732
03/22/2023, 11:50 AMgorgeous-airport-54386
03/22/2023, 11:50 AMts
tracker.addEventListener('report', onReport)
gorgeous-airport-54386
03/22/2023, 11:51 AMtall-sundown-41732
03/22/2023, 11:51 AMtall-sundown-41732
03/22/2023, 11:51 AMgorgeous-airport-54386
03/22/2023, 11:51 AMgorgeous-airport-54386
03/22/2023, 11:52 AMtall-sundown-41732
03/22/2023, 11:53 AMtall-sundown-41732
03/22/2023, 11:53 AMtall-sundown-41732
03/22/2023, 11:53 AMhappy-knife-63802
03/22/2023, 1:49 PMhappy-knife-63802
03/22/2023, 2:03 PMhappy-knife-63802
03/22/2023, 2:09 PMkind-account-66413
03/22/2023, 5:45 PMHX-Location
. I think definitive or recommended direction would help users and folks on the fence and I would be interested in hearing your thoughts. Thanks!some-airline-73512
03/22/2023, 5:54 PMripe-action-67367
03/22/2023, 6:06 PMnumerous-agent-22346
03/22/2023, 6:06 PMmysterious-toddler-20573
03/22/2023, 6:09 PMapp-canvas
etc.some-airline-73512
03/22/2023, 6:17 PMsome-airline-73512
03/22/2023, 6:18 PMmysterious-toddler-20573
03/22/2023, 6:19 PMhx-boost
and then getting more elaborate from there. Most folks end up w/ multiple templates and controller end points to take advantage of the natural shape of web applications (w/ URLs for resources) etc. Broadly my htmx apps look a lot like my pre-SPA applications, just w/ some finer-grained templating and end points.kind-account-66413
03/22/2023, 6:30 PM