I'm having trouble getting my component to receive data from the backend server using sse (server side events).
When I access the api endpoint directly, I see that messages are being received over time as expected. However, when I try to call it using Angular, it doesn't seem to work properly.
The backend indicates that the endpoint was called in both cases.
Here is the backend code written in Flask:
@bp.route('/stream')
def stream_text():
def generate_text():
# Generate the text in sections
sections = ['Section 1', 'Section 2', 'Section 3', 'Section 4']
for section in sections:
yield section + '\n'
time.sleep(0.5)
return Response(generate_text(), mimetype='text/event-stream')
And here is the frontend code written in Angular:
let eventSource: EventSource = new EventSource('/api/chat/stream'); // The URL is correct
eventSource.onmessage = (ev: MessageEvent) => {
console.log(ev.data) // This does not display any data
}
I am trying to configure Angular to receive sse data gradually over time rather than all at once.