Reputation: 902
I love foalts and I am currently using it in a project. But I have feature that requires server-sent events (SSE) but I am not able to implement a response.write on the return response. But I am able to write the headers to have "'Content-Type', 'text/event-stream'"
The only challenge is creating a new res.write()
res.write(sseFormattedResponse); // express example
Thank you for your assistance in advance
Upvotes: 1
Views: 95
Reputation: 82
In this situation, you can create a ReadableStream
, named for example myStream
, and create with it a HttpResponse
as follows:
return new HttpResponseOK(myStream, { stream: true })
or in you case:
return new HttpResponseOK(myStream, { stream: true })
.setHeader('Content-Type', 'text/event-stream');
Upvotes: 0