Replies: 1 comment
-
I've found the solution
Here is the full endpoint: const start = async () => {
// Initialize Payload
// ...
app.get('/stream', (req, res) => {
console.log('server: Client connected')
res.setHeader('Content-Type', 'text/event-stream')
res.setHeader('Access-Control-Allow-Origin', '*')
const intervalId = setInterval(() => {
const date = new Date().toLocaleString()
console.log(`server: Sending ${date}`)
res.write(`data: ${date}\n\n`)
}, 5000)
res.on('close', () => {
console.log('server: Client closed connection')
clearInterval(intervalId)
res.end()
})
})
app.listen(process.env.PORT || 3000)
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello!
I have problem when implementing SEE between Payload and a simple html & JS use EventSource
I've tried to implement the endpoint from collection and direct express route. Both seems sending the data, but not received.
The endpoints:
server.ts
Also tried in collections enpoint
Both have same output from server, it was sending the data
But not received anything from Html
Have anyone experienced on implementing SSE?
Thank you in advance!
Beta Was this translation helpful? Give feedback.
All reactions